CreateVehicleServerSetter (Serverside Spawned Vehicles) Despawning

Hey, I wanted to share some knowledge about a bug that causes vehicles to despawn, even when they’re spawned on the serverside. Normally, serverside spawning should prevent despawning, but it doesn’t seem to be working as expected. I’ve done a lot of testing and debugging with many players to gather as much information as possible.

FiveM Basic Information:

  • Client: Both Release and Beta version
  • FxServer Version: b7604
  • Bug Category: Affects both client and server side

Here’s what I found:
During debugging, I created a small script to check all vehicles using the GetAllVehicles function on the server side. This allowed me to check the last position, owner, and network ID of the despawned vehicle. First, I cached all vehicles and then checked if they still existed. I observed that despawning only occurs when a player owns the vehicle. I’ve never seen a despawned vehicle with the owner being “-1” (indicating the server).

Some information from our community suggests that despawning happens when entering any type of interior (MLO) while the vehicle is still within your proximity, thus making you the owner. It seems like some sort of client-side “clean up” occurs at this point. The game mistakenly believes it no longer needs the vehicle and deletes it on the client side. We suspect that once a client takes ownership of the vehicle, the clientside behavior mirrors what happens with client-spawned vehicles: it gets deleted when the game perceives it as unnecessary.

We’re still in the process of debugging this problem to find a solution as quickly as we can. From my perspective, it appears to be a clientside issue that could potentially be resolved by identifying the function responsible for cleaning up vehicles on clientside.

1 Like

Experienced something similar with players on our servers, but it only seems to affect random individuals. I never had it happen to me, but plenty of players reported similar experiences/issues with server-side spawned vehicles.

I have seen many problems that usually relate to some sort of sudden change of player position (aka “teleport”). As you already mentioned with the following:

Maybe there is a difference between “slowly going out of scope” and a sudden “teleport over 1000+ meters”. I would assume the latter can prevent some sort of handshake when trying to transfer ownership back to the server as the entity is simply immediately deleted?

When I’m doing calls/screenshare with customers to test out specific edge cases they might have with my scripts, I often see them using teleports or flying really fast using noclip. And I find many things just by looking at their screenshare or they tell me about certain things happening when doing so (unrelated to my scripts). Then I ask them if it also happens without teleporting/noclip and the answer is usually that their issue does not occur anymore.

There is a whole heap of issues I’ve seen like that but nothing I can officially confirm by myself but all of them usually relate around (de)spawning of entities (vehicles, objects, peds) especially with other players in proximity.

Server-side vehicles currently aren’t persistent and can despawn.

same here. Did you guys ever figure it out?

make use of orphan natives and sv_protectServerEntities

@Manason can explain in more detail but I believe we spawn client side then sync it, it’s too unreliable even with all the recommended methods.

Does that convar actually help or is it also a “maybe” like SetEntityOrphanMode where vehicles can still disappear?

it prevents clients from being able to delete vehicles, it allows orphan mode to work as intended (orphan mode solves some cases where the server will try to delete the entity, the convar will prevent any client attempts)

1 Like

Thank you for the clarification! :slight_smile:

Does that include scripts that use DeleteVehicle/Entity on client side?

And does it also prevent the following case:

  • Client drives vehicle
  • is completely alone, no other player in sync range
  • Client crashes (or suddenly disconnects etc)
  • Vehicle is just gone without reference, no entityRemoved event called

Has not happened to myself but seen several times in clients servers. That’s the sole reason I still have a loop running that checks for these “vanished” vehicles.

1 Like

Any attempt from a client to delete an server-setter entity is rejected, with similar checks on the client to prevent any flickering/de-sync caused by removing the entity locally on that client just to have it get re-acknowledged instantly. Never heard of that following case, but if its related to the client sending a deletion request then it should be solved

1 Like

I’ve been using this native for months now. This post is quite old the native didn’t exist back then, and I had forgotten about my post. sv_protectServerEntities & SetEntityOrphanMode did fix the despawn issue for me. No issues at all.

1 Like

It’s great that we now have a fix for inadvertent server side vehicle deletion. I’ve been using client spawned vehicles since I’ve run into issues with setting vehicle properties for server owned vehicles. If you teleport the player into the vehicle, you can guarantee ownership, but otherwise I haven’t been able to consistently guarantee vehicle ownership or devise a method to reliably set properties.

Have any of you had any luck with creating trains on the server side with this native yet? So far every client method I’ve seen just results in the same desync, ghosted trains etc. No matter what script I’ve tried. Even with 2 people testing with 20-30 ping each as hosts. More players just makes the situation worse.

Its not possible to spawn trains using CREATE_VEHICLE_SERVER_SETTER as the required sync nodes aren’t created/populated with this native. Regardless if it gets given a bad host with high ping/packet loss then you will run into similar issues with train desync.