Jump to content

Spam new entity creation


Recommended Posts



In my mod Zombiome (https://community.7daystodie.com/topic/20269-zombiome/), each client / player starts a local coroutine that, amongst others, create new entities. It may be quite intense (peaking at 1 entity /seconds / client), depending on the biome effect.


Entities are created with

        int entityClassID = EntityClass.FromString(entityName);
        Entity entity = EntityFactory.CreateEntity(entityClassID, pos);


CreateEntity() will increment a counter to create the id of the new entity (EntityFactory.nextEntityID ++). As I understand, this sends some NetPackage message (and creates some local entity object), but the entity is not available right away (via World.GetEntity(entityId)). I need to wait for the callback of the netpackage to be executed before seeing the entity in the world. Fine for synchronization.


No problem for a single player. Now, I wonder what happens in multiplayer:

- The nextEntityID counter is only local. So if multiple clients simultaneously spam entities (before getting the message of the other player), they end up using the same entityId in their request (while each wants to create a separate one).

- I do not see a different initializer of nextEntityID  (like 0 for player 0, 1e6 for player 1,...) that could ensure the range of entity ids are different for each client.

- I do not know how the game handles multiple entity creation requests with the same id, but I have observed some de-synchronization in zombiome, where each player would only see the entities it created, not the one from the other players (not 100% sure as there were a few bugs happening before, sounds like a good suspect though).


So I wonder how does the game solves this issue when it creates entities. If the id range are the same on each client, the only answer that makes sense to me is

"Only the main player spawns entities, and it does so at other player's location too"

1) Can someone confirm that ?

If that's the case, how does the game determine if the local player is the main player ?


Bonus questions:


2) After creating entity, if I want my code to interact with it (eg buff, move), I will wait/loop until the entity becomes available (World.GetEntity(entityId) != null), and then interact. Even in single player, I have already seen the following: the loop wait for 2 second and finds the entity (first time when World.GetEntity(entityId) != null), but a few seconds later, the entity is no longer in the World. I suspect EnumSpawnerSource.Dynamic to drop the entity because it is too far away from player, so I changed to Static, but I wonder:

- Is it the correct approach ?

- Should each client wait for previous entity to be in world before requesting to spawn the next one ?


Thank you in advance !

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...