I create a map with around 200 objects in this way, but I get this error, I don’t get it when I add Wait(500). Is this a bug? How can I solve it?
“Warning: NETWORK_GET_NETWORK_ID_FROM_ENTITY: no net object for entity (script id xxx)”
client.lua:
for k, m in pairs(MapDetails) do
if xPos ~= nil and yPos ~= nil and zPos ~= nil then
local object = CreateObjectNoOffset(modelHash, rxPos, ryPos, rzPos, true, false, false)
local objnetid = ObjToNet(object)
end
end
It’s not a bug. Entity creation does not happen on the same tick. object
will not have the exact ID of the entity until that entity is created, that’s why you get the error, but not when you don’t wait.
The correct way to do this is:
--lua. client-side.
local object = CreateObjectNoOffset(modelHash, rxPos, ryPos, rzPos, true, false, false)
while not DoesEntityExist(object) do --we wait until the object is actually created and acknowledged by the game
Citizen.Wait(1) --or ~10
end
local objnetid = ObjToNet(object)
EDIT: FYI, this might not work for objects that are not close to the player, because those might not actually get loaded. Instead of DoesEntityExit
, you can also try DoesObjectOfTypeExistAtCoords - FiveM Natives @ Cfx.re Docs, but it’s most likely slower.
This is not true, on the client the this will be instantly created as long as the client has usable network object ids.
On the server this also true for non-rpc natives (CreatePed, CreateObjectNoOffset, etc)
Example Code of this working perfectly fine:
async Coroutine CreateObjectRdr() {
var ped = PlayerPedId();
Vector3 pos = GetEntityCoords(ped, false, true);
var model = Utils.GetHashKey("p_windsorchair03x");
RequestModel(model, true);
while (!HasModelLoaded(model)) {
await Wait(0);
}
var chair = CreateObject(model, pos.X, pos.Y, pos.Z, true, true, true, true, true);
var netId = ObjToNet(chair);
Debug.WriteLine($"{chair} {netId}");
}
its just working 70-80 object, but try 150-200+ object please.
This is expected behavior, you can only have 80 networked objects.
I found another solution, my goal is to change the routing bucket id of the objects.
Sorry for bumping this, but do you know what the limit is as of 2024? Where to check total networked objects?
I’m curious… we have issues with vehicles despawning EVEN while driving them. But mainly, we spawn one (client sided spawn method), it throws a warning. Saves to cache anyways. Then despawns on us and shows another warning. The depsawning happens randomly no set time when it does it. Sometimes you can drive for a while no problem then other times it despawns in 2 seconds on you.
Could this somehow be related to a limit being hit of networked objects (especially with more players in server) and then it just yeets their vehicle on them?
me too.so what s the net entity limit count.how can i sovel this?
how would i add this to stop the issue from happening to me?