Netcode for RTS

I would like to create a multiplayer RTS game, something similar to Company of Heroes or Warcraft with some physics. What is the best netcode for RTS games?

My initial thought was to send only each player’s inputs over the network, as it seems that most real-time strategy games use deterministic lockstep, and the advantage is low bandwidth. However, from my understanding, Unity’s pathfinding and physics system are not deterministic, so this solution is not applicable.

Another option is to add a NetworkTransform component to each unit. However, this raises an issue with bandwidth. Let’s imagine a 3v3 game where each player has around 20 units. That’s 120 NetworkTransforms, which means tens of Kb/s.

Am I right about all this? Because I’m not entirely sure if I understand it correctly. I would appreciate it if someone with experience in this area could share their opinion.

Is it even possible to create an RTS multiplayer game with the current state of Netcode for GameObjects/Entities?

One NetworkTransform per unit, or generally synchronizing every unit’s transform changes every tick. does not scale beyond a few dozen units. Deterministic behaviour is the only way to scale up a network game to several hundred units, and beyond.

This is still achievable within Unity. For instance, no RTS that I know of uses physics to influence the game’s units. Every bit of physics is fake, predetermined behaviour or simply animations. Every real physics is purely visual, not relevant to gameplay, does not need to be synchronized with every client (visual fx are allowed to look differently per client).

Pathfinding in an RTS game is typically still grid-based, no matter how smooth the terrain might look like. Deterministic pathfinding for grid is not that hard to implement, you may even get that from the store.

Lastly, you can use ECS to get deterministic physics and use Netcode for Entities. The learning curve is however quite dense. Not steep, dense, on purpose, because it’s relatively easy to make it work but its quite another thing to parallelize it and then still speed it up by another factor of tens “simply” by gaining a natural understanding of how CPUs like to churn through data, how their caches work, what vectorization is, how data is laid out in memory, and how to write data structures and algorithms that make the best use of this.

1 Like

You are right about this. Out of the box Unity doesn’t provide determinism and just sharing input comes with plenty of downsides.
But: Unity’s expandability is almost endless, so there is a solution:
Quantum is a deterministic multiplayer game engine which ties seamlessly into Unity. It provides the components, APIs and tool set to write deterministic systems so you actually don’t have to worry much about the networking anymore. Hook up the input you need and it does not matter if there are two, eight or up to 64 players. Or just one. Or several on one client and others remote. There is a Bot SDK, so you can make sure players always have something to do.
Check out the Quantum RTS Sample.

In Unity 6, if I open Multiplayer Center and select a game genre, I can see in the Netcode Architecture a few options. One of them is Deterministic Lockstep… if I select it, it says Unity does not provide it… so I guess there is someone out there who provides such an implementation?!

Photon Quantum is such a solution (also see previous post).

I do wonder why they say that RTS requires deterministic lockstep. IMO that’s not an accurate but it depends on the type of RTS.

Determinism helps to lower bandwidth the more units you have but most RTS are primarily around 200 units at most, so this would work well without determinism although at higher traffic.

But you can employ some tricks eg simulate multiple units as a single network entity if they always stay in formation and pathfinding/collisions cannot block individual units of the group. As is moving units logically on a grid but visually they can have any position. That would also simplify pathfinding.

Here’s a really cool article on that subject with a unique approach, from Planetary Annihilation:

They do not do lockstep. They use… curves.