Client unable to enter vehicle when distance culling radius has been increased

1. Environment information
Production client, recommended server artifacts (5562), game build 2189

2. Description
A server-side vehicle is spawned using ‘CREATE_AUTOMOBILE’.
Entity distance culling radius is set to 1500 meters on the created entity through a native.

  • Client 1 is near the spawned vehicle and gains vehicle ownership
  • Client 1 leaves the area to a location which is ~1200m away from the vehicle.
  • Clients 2 comes near the vehicle
  • Clients 2 tries to enter the vehicle

3. Expected behaviour

Client 2 is able to enter the vehicle.

4. Actual behaviour

Client 2 gets frozen when trying to enter the vehicle.

5. Reproducing the bug

  • Launch two clients (-cl2)
  • Place both clients at the same position - command /tp2
  • Place client 1 near the vehicle spawn - command /ped
  • Spawn the vehicle - command /veh
  • Leave the area with client 1 - command /tp2
  • Enter the area with client 2 - command /ped
  • Try to enter the vehicle with client 2 - you get frozen
CODE - Reproducing - server.lua
local vehicle

local vehicleSpawnPos = vector3(2758.566, 1376.277, 24.519)
local vehicleSpawnPedPos = vector4(2755.7, 1376.0, 24.52, 270.0)

local distance1260Pos = vector3(1512.252, 1519.996, 106.725)

RegisterCommand('ped', function(source)
    local playerPed = GetPlayerPed(source)
    SetEntityCoords(playerPed, vehicleSpawnPedPos)
end)

RegisterCommand('veh', function()
    local CreateAutomobile = GetHashKey('CREATE_AUTOMOBILE')
    vehicle = Citizen.InvokeNative(CreateAutomobile, GetHashKey('asbo'), vehicleSpawnPos)

    while not DoesEntityExist(vehicle) do
        Citizen.Wait(0)
    end

    SetEntityDistanceCullingRadius(vehicle, 1500.0)
end)

RegisterCommand('tp2', function(source)
    SetEntityCoords(GetPlayerPed(source), distance1260Pos)
end)

RegisterCommand('dv', function()
    DeleteEntity(vehicle)
end)

Video of reproducing the error using the steps provided above: 2022-07-28 16-15-41

6. Speculating on the causes

Generally, the vehicle driver has ownership of the entity. When client 2 tries to enter the vehicle, he is unable to get the ownership from client 1 and can’t enter the vehicle. As soon as client 1 comes back to the vehicle, client 2 gets unfrozen and enters the vehicle successfully (seen in the video as well). Probably because the culling distance which was set is more than the default OneSync distance.

Backstory

Was trying to achieve persistent vehicles that wouldn’t despawn. Spawned 200 vehicles throughout Los Santos to test this. Vehicles spawned through CREATE_AUTOMOBILE are persistent when the server is empty / you are alone in the server. When multiple clients are moving around, the vehicles started to despawn rapidly.

My second approach was to increase the entity distance culling radius (which caused this bug report) as was suggested in some places. When trying it out, a lot of the players were unable to enter their vehicles, presumably because the ownership of the created vehicle went to someone far away.

This bug has been noticed in the past too, but we have not been able to reproduce it reliably until now. Using SetEntityDistanceCullingRadius makes it reproducible (although not sure if the cause is same).

Anyway, I assume the player should not be frozen trying to get into the vehicle no matter what. Or is this really a side-effect of using this native? Apologies if it is.

1 Like

Overriding culling radius is not supported, and is a pull request that got accidentally merged. You should not ever use that option (especially not with a greater value than the default), and any scenario using it is better served using other ways to e.g. invoke client-side commands or whatever you want to do.

There was a discussion about this in the server owner chat room a while ago (which sadly is not public yet, and one can’t easily snapshot messages from a Discord chat either) that also showed another similar bug here, but that one applied even when not setting a radius, and it’s separate from the scenario with a larger radius set being broken, as that scenario is meant to be broken (the player owning the entity must be created for the entity to be usable in this way, which isn’t ever going to be the case if the entity is outside the owner’s radius) at this time.

Similarly,

this would also be a separate bug and making up workarounds, as you can see, doesn’t help either. :stuck_out_tongue:

1 Like

When researching this native, I did not find any information that it shouldn’t be used. Looking through messages / posts where this native was mentioned, I did find ~5 messages from even you on Cfx Disc guild, where you suggested / mentioned it in some cases (although which weren’t directly related to my goal here).

Based on that information, I did think it was a valid native (not something that’s there by accident), that maybe could be used for a workaround here.

So vehicles created using CREATE_AUTOMOBILE are indeed supposed to be persistent? I found conflicting information about this. If so, I’ll make a bug report about that instead, as I do have a repro for that as well.

Until disowned from script, yeah, these should stick around.

CREATE_AUTOMOBILE discussion continued from here Vehicles created server-side using CREATE_AUTOMOBILE are not persistent

I guess the documentation stance on ‘I want persistent entities, how do I do it?’ should be changed too in that case, as this is a recommended native to use (at least for CreateVehicle), as suggested here:

OneSync - Cfx.re Docs
If you want to stop this entity from ‘despawning’ when far away, you could always set the entity culling radius to a very large number by using the following native: SetEntityDistanceCullingRadius

Ouch, guess someone wrote it there too. I’ll try to pick that up with the docs folk.

1 Like