[SOLVED?] Assign a net id to an existing world object

Hello, i was wondering if someone had an idea on how to do this.

Let me explain. The game map has already placed al lot of objects. every object that has physics has an entity id so is easy to diference one from other even if it has the same model. For vehicles and peds is fine, because they are synced and they have a unique net id. But when it comes from objects they doesn’t need to be synced because the map already loads the position of them. So it would be a waste of bandwidth to have it on sync.

So, i understand that they doesn’t need to have a net id, but it would be very useful to store some data on it and share it across the other clients. As long as i know is posible to assign a net id to a new object with:

“OBJ_TO_NET”: But with an existing world object after firing a warning (not net id found) it returns an unique id that could be useful for this purpose, but is diferent on each client so i can’t use it.

There is any way to send that id to the whole clients?

I also tried these functions:

SetNetworkIdCanMigrate(netid,true);
NetworkSetNetworkIdDynamic(netid,true);
SetNetworkIdExistsOnAllMachines(netid,true);
SetNetworkIdSyncToPlayer(netid,playeriteration,true);

*Netid = obj_to_net(entity) *playeriteration = a loop from 1 to 32

All of them return “no object id for NETID”.

Any idea?

Thank you.

NETWORK_REGISTER_ENTITY_AS_NETWORKED should create a network object for any entity that doesn’t have one yet.

1 Like

I’ve just tried that function, it doesn’t work as expected but is close.

After using NETWORK_REGISTER_ENTITY_AS_NETWORKED , Network_Get_Entity_Is_Networked still returns false, however if i call OBJ_TO_NET just after, it doesn’t fire a warning and returns a real net id, and the other functions neither.

So could be useful, but i still need to do more test.

Thanks for your answer.

Edit:

function entityNetCheck(entity)
		if (NetworkGetEntityIsNetworked(entity)) then
			print("Networked");
--This is never reached even executing  the function two times.
		else
--This always happens
			print("Not networked");
			NetworkRegisterEntityAsNetworked(entity);
			local netid = NetworkGetNetworkIdFromEntity(entity);
			print("entity:"..entity) -- just to ensure the entity is the same every time.
			print("Netid:"..netid) -- A real net id.
--If i do a isnetworked check returns true, so why it returns false a second time?.
		end		
end

It has no sense, or i’m blind.
Is it hardcoded to not being able to do this to world objects?

I run out of ideas.

Edit2:

It seems to work if the world object is declared as mission entity:

SetEntityAsMissionEntity(entity,true,true);

But probably is not the best solution to have a lot of objects around the map declared as “important”.

:thinking: