Culling Entities wont work properly if entity is already far away and its nearby to other players

Hi, im trying to create racing resource where you can race with local peds and vehicle.

im trying to use SetEntityDistanceCullingRadius Server Native to make the Task eg. taskvehiclechase works without issue even if the entity is very far away.

i read a lot about this native too in the forums and nobody reported or have this issue yet.

this will work without any issue if you are the only player in the server

or your only the player inside the culled distanced grid

. eg. 2000 radius culling is called to server side for entity.

The issue:

is if the entity is culled to large numbers like 2000.
and the first owner of entity is not moving or stay on the same spot while the entities are moving to assign locations, the problem will start if the Entity is nearby to other player. ( out of scope of first owner normal culling radius eg 400.0)

the entities are teleported back to first location of the spawned locations where the first owner.

More Info:
Peds and Vehicles Entities are spawned via Server RPC Createped and CreateVehicle.
Tasks are used in client side from the Host of race for example.

  • server side.
RegisterNetEvent('renzu_race:SetCullingRadius', function(data)
	inrace[source] = true
	SetEntityDistanceCullingRadius(NetworkGetEntityFromNetworkId(data.ped),4000.0) -- try set culling radius, prevent ped from stoping the task or having entity deleted if owner is very far away
	SetEntityDistanceCullingRadius(NetworkGetEntityFromNetworkId(data.vehicle),4000.0)
	SetPlayerCullingRadius(source,4000.0) -- just incase
end)
  • server side.

This is the entity dummy to followed by Taskvehiclechase

RegisterNetEvent('renzu_race:MoveDummy', function(net,coord)
	--print(NetworkGetEntityFromNetworkId(net),'moved',net,coord.x,coord.y,coord.z)
	SetEntityCoords(NetworkGetEntityFromNetworkId(net),coord.x,coord.y,coord.z+5.0)
end)
  • Client Side
            local ped = NetworkGetEntityFromNetworkId(v.ped)
			local vehicle = NetworkGetEntityFromNetworkId(v.vehicle)
			SetEntityInvincible(NetworkGetEntityFromNetworkId(dummy),true)
			--SetPedIntoVehicle(NetworkGetEntityFromNetworkId(dummy))
			SetBlockingOfNonTemporaryEvents(ped,true)
			TaskSetBlockingOfNonTemporaryEvents(ped,true)
			SetPedConfigFlag(ped,294,true)
			--TaskVehicleMissionPedTarget(ped,vehicle,dummy,8, 200.0, 4980736,1.0,100000.0,true)
			TaskVehicleChase(ped,NetworkGetEntityFromNetworkId(dummy)) -- need to do this logic to make the ped driver drive aggresively and faster, instead of using any other taskvehicle
			SetDriveTaskDrivingStyle(ped,4980736)
			SetTaskVehicleChaseBehaviorFlag(ped,1,true)
			SetTaskVehicleChaseIdealPursuitDistance(ped,1.0)
			SetDriveTaskCruiseSpeed(ped,300.0)
			SetPedAlertness(ped,3)
			SetVehicleUseAlternateHandling(vehicle,true)
			SetPedAsCop(ped,false)
			SetPedKeepTask(ped,true)
			SetEntityLoadCollisionFlag(ped,true)
			SetEntityLoadCollisionFlag(vehicle,true)
			print('set task', ped, vehicle)

other issue:
The thing that i have seen is i think the entity is re assign to other player who is nearby
and sometimes the tasks are forgotten and stay not driving.
or teleported back to original spawned location.

workarounds
i have tried setting the radius to default 0.0 or not use it
the teleport issue will be fixed but ofcourse the task will be forgotten once the entities are not nearby to any players

Last Method
im trying to avoid this , The last thing i am thinking is if this is a normal behavior of one sync.
i should just leave multiplayer feature with locals and i should just create a different world for the each race session for every single player if racing with local entities.

other info:
the entity id and net id are still valid and entity is existing
other player is in the other side like 1000 radius ( one of checkpoint )

video
https://streamable.com/uz3z2c

just incase i created an issue in github repo too
Thank

i removed the

SetPlayerCullingRadius(source,4000.0)

teleport bug is not happening anymore

Did you resolve the issue where the entities (ped and vehicle) forget the task set by the player? I think I’m experiencing the same issue.

I also tried setting the entity’s culling radius using SetEntityDistanceCullingRadius().

What I’m observing is:

  1. Seems to work flawlessly when there is only ONE player on the server. I can be across the map and the task will still work.

  2. If there are 2 or more players, then the scenario will work for the closest player and the one far away would not be able to control the entities despite NetworkRequestControlOfEntity() .

  3. If players are within close range of the entities, then it seems like the task will work for each of the player.

It has to do with being “far away” when the entities are spawned? I was hoping setting the entity’s culling radius to something large would fix it, but it only seem to work when there is only a single person on the server.

i use GetScriptTaskStatus

i suggest dont use Player Culling Radius, and even if you set Entity Culling radius to large radius, the entity will still migrate to another nearby player.

also dont use NetworkRequestControlOfEntity,
i use the server to get the network entity owner and pass the Current Task and verify if entity tasks are still active using GetScriptTaskStatus and re run the tasks if its not active.

and the entity ownership can migrate again to you if the Last owner is out of scope from the entity,
only if you set large entity culling radius, but most of the time the second Owner of entity controls the whole session of the tasks, even if the second owner is far away ( > 400 meters from entity )

so far this method works without issue to me, but still risky to apply in live enviroment and not recommended, thats why my race resource are still under observation and unrelease.

1 Like

Much appreciated! Both your hard work here has really helped out!

I’m having he same issue and im spawning an object server side and get the coords of the object client side but the object is too far away and doesnt exist so they come back as nil.

Any work around for this?