# How to manage network spawning?

I'm developing an multiplayer game "from scratch" (not using a big Engine-Suite like Unity but the lower-level libgdx).

Currently I've got a NetworkManager which handles the sending of messages on server side and receiving those with subsequently calling methods on client site.

At the moment the sync between figures works already once they are correct configured and spawned on both ends. Now I'm currently think about the spawning of those objects.

Approach No.1: My first approach was that every time the Server spawned a new (e.g.) player, it will subsequently send a "SpawnObjectMessage"-Object (holding all necessary type and configuration values) to all clients. Clients will than spawn a new player-figure. Now the synchronization works.

Concerns:

• I have concerns with this solution that individual messages could be lost (due to network problems, for example),
• or what happens if a client closes the program in the middle of the game and then starts again and all figures have to be reloaded (as already said : The server only sends the message once as soon as it spawns a player itself).

Approach No.2: The server hold a "model" of all figures (he does this anyway due to some other functionality) and sync this with all clients. The "model" here is a list of objects each one describing values of a figure: The

• prefab/class/type the object is
• if it is spawned of or just created on server side
• is it controlled by a player and possibly the PlayerID
• ... The server will send the complete List (or only the changed entries) to all clients every time some changes occur. The clients will override their local list and subsequently iterate over it and spawn objects if they could not find a corresponding counterpart. If a new Player enters the game or a client restarts the game, the server will resend the complete list to the new client.

Concerns:

• This solution seems a little bit "reactive"
• It maybe not very intuitive
• Maybe I'm overseeing something what will bring problems

Which approach is more common or what concerns are you aware of in such projects?

Since @milk asked how Updates works here is an additional explanation how this will work: The server will send continously update messages (e.g. "UpdatePositionMessage") for every Player-Objects exiting/spawned on server side. Server will keep doing so no matter if clients has successfully spawnend the corresponding counterpart object or not. Clients will simply ignore updating objects which can't be found. This update-mechanism is used in both approaches described above.

• For approach 1, how do you plan to do updates? Do you have a separate UpdateObjectMessage that clients would simply ignore if they missed the corresponding SpawnObjectMessage? – milk Feb 27 '20 at 21:48
• Yes it's exactly like this but this is not only for approach 1 since the update-strategy is working always the same after players are spawned on both ends no matter how the spawning was realized. Even approach 2 is just for SPAWNING and maybe for REMOVING objects - not for updating. I've edited the question with additional informations. – Marc M Feb 27 '20 at 23:52
• Are you using TCP? Messages can't be lost by TCP, only delayed (in the same order). Which is convenient, if your game is slow-paced (e.g. used by Minecraft, noting that when it was designed, nobody thought there would be much fast PVP) – user253751 Feb 28 '20 at 17:58
• @user253751 Note that TCP won't handle disconnects longer than a certain timeout, so it's not a magic bullet. If a player's PC crashes, you'll need a way to get missed messages – Mars Mar 2 '20 at 7:02