This may (and probably is a stupid question) but I can’t find the answer anywhere.
Using the new network system for Unity 5.3, All of my objects have unique netIds from the networkIdentity component.
So is there a way to do a search if I only know the netID (say it was passed through an RPC function) of the object.
I guess what I am looking for is there a function like this:
GameObject temp = (GameObject)GameObject.find(NetworkIdentity.netId)
I think I could write one myself, by finding all game objects with network identities and then looking for the right one, I just feel there is a more elegant solution.
Thanks,
BM
Hello @BlackManta
You can give name of that gameObject as its NetworkIdentity.netId
gameObject.name = NetworkIdentity.netId.toString();
and then you can find out that gameObject by its name.
GameObject temp = (GameObject)GameObject.find(NetworkIdentity.netId.toString())
ClientScene.FindLocalObject ?
Found this built-in dictionary in ClientScene that does precisely what we’re looking for:
https://docs.unity3d.com/ScriptReference/Networking.ClientScene-objects.html
ClientScene.objects
public static Dictionary<NetworkInstanceId,NetworkIdentity> objects;
Description
This is a dictionary of networked objects that have been spawned on the client. The key of the dictionary is the NetworkIdentity netId of the objects.
Very simple to use:
using UnityEngine.Networking;
...
// Assume some var targetNetId
var targetNetworkIdentity = ClientScene.objects[targetNetId];
HTH!