I have a multiplayer RTS game with every unit assigned an ID.

How can I efficiently send across a network the units selected by a player? For example, Starcraft 2 has upwards of 200 units per player and each player can select a maximum of 255 units at a time. How can I implement such a system with reasonably low response time and bandwidth?

Should I bother sending IDs? Should I perhaps send a bitmask with each bit defining whether each unit is selected?


2 Answers 2


There is no reason to communicate over the network when the player selects units, because in most games just selecting a unit has no game-mechanical consequences. So this is an information which isn't relevant to the server or to the other players.

But what would be important is when the player gives a command to one or more units. When issuing a move-command to a bunch of units, the client would send the IDs of the units and the locations to which they were sent. When we assume that a unit has a 2byte ID (allowing up to 65000* units in the game), the target coordinates are in tiles and the maximum width and height of a map is less than 65000*, we have 6 bytes per unit move command. When the player sends a move-command for 200 units at once, we have 1200 bytes.

The best RTS players perform up to 200 actions per minute, which would be about 3 actions per second. When each of that actions is a command to 200 units, this would require a bandwidth of 3600 bytes/s. Let's round this up to 4 kByte/s with overhead.

4 kByte/s is half the bandwidth of a 56k analog modem which was a standard consumer-grade internet connection in the 90s when Starcraft 1 was released. Assuming that the incoming bandwidth is about the same, we see that a duel between two world-class Starcraft players was just within the bandwidth capabilities of the average household when Starcraft 1 was released. Considering that not every action will be a command to 200 units at once and that the average player performs much less than 200 ApM, we see that an 8 player online match between casual players was definitely possible that way.

*65536 when you want to split hairs

  • 2
    \$\begingroup\$ Ah, thanks for the input. You definitely introduced me to a better perspective on bandwidth and I now realize that if others take 1200B lightly, I should be able to take the 8B lightly using a flag for every unit instead of sending their ID's. I only need 64 potential selected units per player so this will work perfectly for me. Thanks! You've cured my worry-wurt concerns over bandwidth usage. \$\endgroup\$
    – JPtheK9
    Mar 6, 2015 at 1:53
  • \$\begingroup\$ @user2994455 That means you will need a 64bit bitfield. When you have only 64 units per player, an 8bit integer would be sufficient as an ID field. So when your player gives a command to less than 8 units at a time, your bitfield solution would require more bandwidt. Think carefully how many of your players actions will be mass-commands and how many will only involve a single unit... but seriously, what are we talking about? This is 2015. 10Mbps internet connections are normal nowadays. \$\endgroup\$
    – Philipp
    Mar 6, 2015 at 8:49
  • \$\begingroup\$ I was planning on compressing the data into an 8B int. Are bitfields a significantly better option? \$\endgroup\$
    – JPtheK9
    Mar 6, 2015 at 17:53

Most of RTS game like starcraft / warcraft etc only transmit player input between clients. After the game engine does the simulation with the input received. It's lighter for the network to only send the player's inputs.

look at this post : How to implement lockstep model for RTS game?

  • \$\begingroup\$ I know how RTS games network and I highly doubt they send 'Player started moving camera to the right' and 'Player drew box from (15,20) to (50, 80)'. \$\endgroup\$
    – JPtheK9
    Mar 5, 2015 at 22:55
  • \$\begingroup\$ I would add that there are quite few games that do this because its incredibly hard to achieve perfectly. \$\endgroup\$
    – akaltar
    Mar 6, 2015 at 1:03
  • 1
    \$\begingroup\$ Looking at a Starcraft 2 replay it seems unit selections are saved (single unit, mass units, etc), including for remote players. Which means: they are sent over the network. \$\endgroup\$
    – oxygen
    Jul 12, 2017 at 18:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .