Free Unity3d Script: Find Objects By InstanceID

Here is a script that I use a lot for troubleshooting busy scenes. It will select objects and components in a scene by instance ID.

Download SelectObjWithGID.cs

What is an Instance ID?

In Unity all GameObjects, Assets and Components have an Instance ID. This ID is an internal number used by Unity that uniquely identifies each object or component. If you have one thousand bullets in a scene named “Bullet (Clone)” then each of these bullets has a different Instance ID. You can get an objects Instance ID by calling GetInstanceID().

Unity allows many objects to have the same name, but every object has a unique Instance ID. It is good practice to include an objects instance ID as well as its name in debug statements:

Debug.LogError("Something terrible happened that should never happen to object '" + myComonent.name + "' id=" + myComponent.gameObject.GetInstanceID());

Output:

Something terrible happened that should never happen to object 'Bullet (Clone)' ID=-34572123

With this you can find which one of a thousand bullets reported an error.

How To Use The Script To Select Objects By Instance ID

  1. Download the script file and put it in a folder in your project. The folder MUST be called “Editor”
  2. Choose Window -> Select Object With Instance IDSelectObjByID
  3. Enter the instance ID in the text field and click “Select”
    SelectObjByID2

Download SelectObjWithGID.cs