entityCreated triggered again after entity deletion
What happened?
Server creates an entity with CreateVehicle, it exists some time, it's deleted by the server with DeleteEntity, few seconds after entityRemoved is triggered and the entity was removed, another entityCreated event is triggered for the same entity model, net ID but different handle.
Expected result
entityCreated is not triggered after entity deletion for the same entity
Reproduction steps
- Create a vehicle server-side using CreateVehicle
- entityCreated is triggered
- The entity exists some time on the server
- The entity is deleted server-side using DeleteEntity
- entityRemoved is triggered
- Few seconds later, entityCreated is triggered for the same entity model, same net ID but different handle
Importancy
Unknown
Area(s)
ScRT: Lua, FiveM, OneSync, Natives
Specific version(s)
Artifact Version 25770
Additional information
This happens once in every few hours over hundreds or thousands of entities created/deleted, I didn't find any specific cause. I'm sure that no actual entity is spawning when the second entityCreated is triggered, but it seems like a delayed event bug.
Now that I think of it, could it be that the entity owner is trying to fight the server's DeleteEntity call by trying to spawn the entity again, and if so, how to prevent that?
Sounds like some anticheat behaviour
Yes, we create all networked entities server-side, we whitelist their handles and listen entityCreated & entityRemoved for checks. What's wrong with that?
We have also encountered the issue when our server reaches around i think 100 players could be when we are above 128 players
could it be that the entity owner is trying to fight the server's DeleteEntity call by trying to spawn the entity again
That is my thought process as well. Perhaps you delete the entity while it's in the process of migrating to another owner? Would explain why it happens so rarely. Not sure if ytou can do anything about it sadly, other than check if the entity exists in the event...
We already check every time inside entityCreated with a 2 sec pre-delay if the entity exists and that check is passed in this case. That tells me that the entity is removed by the server but a client refuses to remove it and re-syncs it and the server accepts that.
So server-side DeleteEntity can be overriden by a client.
One solution is setting strict lockdown mode? Any others?
What i have noticed when it comes to car when they are spawned sometimes it spawns in the entity and in a millisecond it delete the handler spawns in a new one exact same vehicle changes net id and owner
i have had this problem for years now
usually happens with 100+ players
I added more debug info. This one happened around 70 players.
- 12:29 entityCreated (Handle 149015, Net ID 364, Model 990262449, Owner 116, First Owner 116)
- 12:43 entityRemoved (Handle 149015, Net ID 364, Model 990262449, Owner 85, First Owner -1)
- 12:43 (right after the previous event) entityCreated (Handle 139271, Net ID 364, Model 990262449, Owner 85, First Owner 85)
Seems to be caused by an edge case with relevantTo being empty & first owner dropping (from ServerGameState). Orphan Mode set to KeepEntity should prevent this behaviour.