Im working on a little plain c# gameserver using an ecs. It follows the principles of the client/server model architecture.

However im often running into the following problem, the server has one or multiple list where items are being added, updated or removed during the frame... and those changes should be broadcasted to all clients at the end of the frame.

So i require some sort of tracking mechanism, i need to track those added, updated or removed items till the end of the frame is reached to send packets.

How is this normally done ? Im glad for any help or tips :)


2 Answers 2


This is a great question actually, and something I've been struggling with a lot in any multi-player systems I've been trying to design.

I've come-up with the following scheme, but I haven't been able to battle-test it yet, and its definitely more geared towards 'slower' games like an RTS and not to shooters or fighting games.

Instead of making these changes immediately in a system I would introduce the concept of commands. Anything that changes that every client/server needs to know about generates a command. For example if the user presses the 'build' button a BuildCommand should be generated.

That BuildCommand should be sent to the server, the server should verify the requirements for this command (does the player have enough resources?) and then validate that command in a message to all listeners.

Clients handle new validation messages at the beginning of each frame. So the new entities/components are created at that time and present for simulation during the entire frame.

Using this scheme you never directly make changes to your entities/components without the others knowing about it.

To make this scheme work even better you could consider running all clients in lock-step and including a frame-number in the validation message so that every client handles a message in the same frame. Be careful though this will lead your game to run as slow as your slowest/laggiest client.

Not every change to an entity/component needs to generate a command. Sound systems, particle systems, graphical systems, etc.. can basically do their own thing because without the other clients needing to know about it. If your simulation is deterministic you will in general only need commands for things that happened because of user input.

Hope this helps! I'd love to know if you settle on this, or another, strategy and what your reasoning was.

  • \$\begingroup\$ Thanks ! :) I guess i will really settle on this... It actually sounds reasonable. The reason i asked this question was some sort of animation system. They are server controlled and each server entity has a animation component with a list of animation triggers for the clients animation behaviour tree. This server side list changes a lot ( Entity walking ? Well set run trigger to true... ) and needs to be synchronized to its clients. Instead of some overcomplicated automatic synchronization solution i will just pick your way and send "AnimationCommand"'s to simulate the synchronisation ^^ \$\endgroup\$
    – genaray
    Commented Feb 24, 2022 at 14:08

This is usually handled by netcode, so there are already tools available so you don't have to think too much about how to handle your user input that thoroughly. I don't know if you're using Unity, but if you are, FishNetworking and Mirror are pretty solid tools for C#.

If you're still looking to do the netcode by yourself, you would need to implement a state system, based on ticks. The server would send the players the changes of the state of the objects within the system at a regular interval. The state memory is what will keep track of all the changes in the order that they happened so they can send that information at the interval you set up.


You must log in to answer this question.

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