Legacy Documentation: Version 4.6(go to latest)
Language: English
  • C#
  • JS
  • Boo

Script language

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

EditorUtility.InstanceIDToObject

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function InstanceIDToObject(instanceID: int): Object;
public static Object InstanceIDToObject(int instanceID);
public 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); } } }