Communicating RTS Unit Selections?

I’m making an RTS game and I’m curious what the industry uses to send over unit selections to everyone. Currently, I’m sending a BitArray with a flag for each unit in a Controller telling whether or not that unit is selected. Are there more efficient ways of communicating unit selections?

Note: I have a decent amount of experience with c# so I’m open to many ideas and suggestions.

I just keep data like selection local-only and don’t send it over the network.

@gfoot Are you implying to simulate all 64 units of a player locally then sync them? Most RTSs send commands rather than simulation data.

Btw, I’ve decided to divide units into groups of 8 for culling and send a BitArray for each group if a unit in the group is selected.

I just wouldn’t sync things like selection events, as they don’t affect the onward simulation.

If you do need to send the selection later, for example because all the selected units are receiving the same attack command, then I guess a bit mask makes sense.

I would consider whether multi-unit commands will be common or not, and if not, keep a more efficient single index version (6 bits for numbers up to 63) for the common case where only one unit is affected.

When 1 unit is selected, there’d be 1 extra byte for the selection header that describes how many groups of units are selected (which is 1). Then there’s the 1 byte that would’ve be used anyways for its ID that describes which unit in the group is selected.

Well i don’t know much about RTS games, but dont you normally run a deterministic system and just send player inputs for everything?

Kind of. You send commands, i.e. units X,Y,Z → Move-> (50,70). Simulating on everyone’s computer by sending mouse position and click events would be extremely difficult.

What I was thinking for my RTS game is to send with each command the list of units that are issued that command, but don’t send the unit list if it’s the same as the previous command. So when someone has selected their whole army and are spamming clicks, they will only send a command of a few bytes each time. (command ID + object clicked ID + vector pos clicked for ~ 8 or 12 bytes).

Currently I was just thinking of using integer IDs for the units, which is a bit of a waste with 4 bytes when the amount of units in the game will stay at max some thousands, so here some bit flag trickery could make for some improvements I guess, but it will take book keeping of what flag is for what unit. I guess 100 bit for 100 units is a big improvement over 3200 bit for 100 units, Even if smaller selection lists get a bit bigger.

You can store a selection of up to 512 units in 72 bytes. This is what I did in Lockstep Framework. Basically, instead of sending unit IDs, send a bunch of flags representing which unit is selected.

I.e.

FlagArray = new BitArray (512);
foreach (Unit unit in SelectedUnits) {
FlagArray[unit.ID] = true;
}
Send (FlagArray);

On the other side, deserialize the selection.

for (int i =0 ; i < FlagArray.Length; i++) {
if (FlagArray[i]) {
SelectedUnits.Add (Unit.GetSelectedUnitWithID (i));
}
}

Like what @gfoot said, I made selection all for local clients. Anything else involving unit interactions would require something else that I haven’t thought about.

I don’t even know what methods are considered useful for UNET… And I’m doing my best to try and use UNET as natively as possible.