fivem icon indicating copy to clipboard operation
fivem copied to clipboard

entityCreated triggered again after entity deletion

Open airbon99 opened this issue 6 months ago • 9 comments

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

  1. Create a vehicle server-side using CreateVehicle
  2. entityCreated is triggered
  3. The entity exists some time on the server
  4. The entity is deleted server-side using DeleteEntity
  5. entityRemoved is triggered
  6. 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?

airbon99 avatar May 15 '26 07:05 airbon99

Sounds like some anticheat behaviour

yorick2002 avatar May 15 '26 08:05 yorick2002

Yes, we create all networked entities server-side, we whitelist their handles and listen entityCreated & entityRemoved for checks. What's wrong with that?

airbon99 avatar May 15 '26 08:05 airbon99

We have also encountered the issue when our server reaches around i think 100 players could be when we are above 128 players

TheRealBablo avatar May 15 '26 09:05 TheRealBablo

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...

Gogsi avatar May 15 '26 09:05 Gogsi

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?

airbon99 avatar May 15 '26 09:05 airbon99

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

TheRealBablo avatar May 15 '26 10:05 TheRealBablo

i have had this problem for years now

usually happens with 100+ players

AngeloneISL avatar May 15 '26 10:05 AngeloneISL

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)

airbon99 avatar May 15 '26 11:05 airbon99

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.

airbon99 avatar Aug 01 '26 21:08 airbon99