Legacy Documentation: Version 4.5.0

Script language:

  • JS
  • C#
  • Boo
Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorUtility.InstanceIDToObject

static function InstanceIDToObject(instanceID: int): Object;
static Object InstanceIDToObject(int instanceID);
static def InstanceIDToObject(instanceID as int) as Object

Description

Translates an instance ID to a reference to an object.

If the object is not loaded from disk, loads it from disk.


Editor Window to enter the instance ID and print the name of the object.

	// Simple editor window that prints on the console the GameObject
	// name given an ID.
	// If no objec is found it prints an error.

class EditorUtilityInstanceIDToObject extends EditorWindow {

var id : int; @MenuItem("Examples/ID To Name") static function Init() { var window = GetWindow(EditorUtilityInstanceIDToObject); window.position = Rect(0,0,160, 60); window.Show(); }

function OnGUI() { id = EditorGUILayout.IntField("Instance ID:",id); if(GUILayout.Button("Find Name")) { var obj = EditorUtility.InstanceIDToObject(id); if(!obj) Debug.LogError("No object could be found with instance id: " + id); else Debug.Log("Object's name: " + obj.name); } } }