Can you search for GameObjects by NetworkIdentity?

Is it possible to find GameObjects by NetworkIdentity? I can imagine some cases where the server needs to run through a list of objects sent to it by a Command, and it seems the best way to do it is to send the NetworkIdentity as a string and then search the Server scene for them.

Some kind of GameObject.Find that takes a NetworkIdentity as an argument would be pretty cool.

My code that autogets the component I need:

  public static T GetFromNetID<T>(NetworkInstanceId netID) where T : Module
  {
  if (GameNetwork.IsServer)
  return NetworkServer.FindLocalObject(netID).GetComponent<T>();
  else
  return ClientScene.FindLocalObject(netID).GetComponent<T>();
  }

Basically

// For server
NetworkServer.FindLocalObject(NetworkIdentity.netID);
// For client
ClientScene.FindLocalObject(NetworkIdentity.netID);
1 Like

Thanks this is just what I need!