Best practice on how to use movements inputs for multiples characters/AI?

Hello there :slight_smile:

I have been working on a multiplayer RTS game, and I am facing a problem that I hope someone could help me with.

So, briefly, what is the best practice to handle player input for the movement of multiple units?

At first, I thought that sending the location of the mouse click to the server, which would then be handled by the AI controller of the character (pathfinding), would be enough for my game. However, there are some limitations to this approach:

  • No client-side prediction
  • With the GAS plugin, no client-side abilities (because the characters are Simulated Proxy)

Then I found a way to resolve these two issues: the character/AI needs to be an Autonomous Proxy. I managed to do that, and it works fine. However, this introduces other limitations… My character needs to adapt its behavior based on a behavior tree (it is an AI with orders from a player). The behavior tree only runs on the server. And since it is now an autonomous proxy, the server cannot make input moves for my character.

I am certainly not the first to try to achieve this, so here I am. How can I handle character AI with player input? =)

Thanks a lot!

First, a disclaimer: I’ve never made an RTS using UE but then again the post starts with “Best practices…” so the OP is obviously fishing for some questionable advice :wink:

Here’s my two cents:

  • Don’t use characters for your units. Characters are irredeemably heavy (especially their movement component) and have a bunch of functionality that you’ll never use. Move simple actors around. Write your own movement prediction and correction - it will be fun :wink:
  • Don’t use a controllers to possess each unit. Controllers have complex network behavior and significance. They are not computationally heavy, per se, but clients have access only to their own controller. Try to figure out how to run an AI behavior on a group of units sharing the same type, command and similar location.
  • Don’t use GAS. That is not a hard “no” but given that you’ve already discarded characters and controllers I see you having quite a hard time running GAS on a bunch of stripped down actors :slight_smile:
  • Don’t use hard collision. Recursively resolving tightly packed collisions can quickly tank your performance. Opt for avoidance (soft push that resolves over time)
  • Do use animation “shenanigans”. The UE animation system is very flexible but slow at scale. I’m not sure about the latest additions to it but definitely research animation LODs, low accuracy animations, animations in vertex shaders etc.
  • Do send you commands to the server and let both the client and the server move the units while gently correcting their position from the server over time. No one cares where the units are exactly until they start shooting :wink:
  • Do make the server THE authority regarding the attacks, health loss and death of units and buildings. Other than that, just make sure it doesn’t look too broken on all clients. After all if the units die at the right time no one cares if they shot 5cm outside their range or if the RoF was a bit off spec at the start.
  • Do research how GAS works to provide the backbone for your unit abilities and parameters. If you can make use of some of their classes, do so even if you don’t use them as intended.

Of course those points are truly and utterly demented so start with what you can hack as fast as possible. Keep those points in mind just to avoid relaying too much on systems that are not well suited for your gameplay. When you hit a performance or technical wall see what of those (if any) can solve it.

Hello @dZh0!
Thanks for taking the time to answer!

I suspected that I would have to migrate to custom Actors/Components at some point due to certain limitations. Your answer just gave me a boost to go in that direction! Even though it seems more complicated. :confused:

However, I was wondering if it is possible to achieve a similar result with built-in engine functionalities? :smiley: I have difficulty to believe that Unreal Engine could not out of the box provides theses functionalities x)

In any case, I’ve started the rework on it, following your guidelines, and I will let you know what the result is. =)

Thanks!

You can have similar results with the built-in functionality. Reading your post, you already have quite a lot of it figured out. You just have to reconcile with the fact that the players are disembodied cameras that send orders to the server and the server does all the work. It won’t be fast or elegant and will go against the “philosophy” of simulating the game on both ends and just correct the clients.

As I said in the end - do whatever gets you there fastest and change your approach when you hit a wall. Make your game modular/decoupled enough so replacements are easy and you can redo parts of it. Don’t spend too much time solving for the particular implementation - the implementation will change.

Moving actors around directly and changing their “health” will get you 70% of the way and can be easily “done better” later on. (transferred to GAS for example) If it took you very little to make you won’t hesitate when you have to replace it. Get the boring thing out of the way (barely working) and focus on whatever is important, fun and unique for your game.

Always assume that everything you make will have to be re-done… because it will be… multiple times.