Version: 2017.4
LanguageEnglish
  • C#
  • JS

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

Submission failed

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

Close

Cancel

public static method InstanceIDToObject(instanceID: int): Object;
public static Object InstanceIDToObject(int instanceID);

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.

#pragma strict
public class InstanceIDToObjectExample extends EditorWindow {
	static var id: int;
	@MenuItem("Example/ID To Name")
	static function Init() {
		// Get existing open window or if none, make a new one:
		var window: InstanceIDToObjectExample = InstanceIDToObjectExampleEditorWindow.GetWindow(InstanceIDToObjectExample);
		window.Show();
	}
	function OnGUI() {
		id = EditorGUILayout.IntField("Instance ID:", id);
		if (GUILayout.Button("Find Name")) {
			var obj: Object = EditorUtility.InstanceIDToObject(id);
			if (!obj)
				Debug.LogError("No object could be found with instance id: " + id);
			else
				Debug.Log("Object's name: " + obj.name);
		}
	}
	function OnInspectorUpdate() {
		Repaint();
	}
}
using UnityEngine;
using UnityEditor;

public class InstanceIDToObjectExample : EditorWindow { static int id;

[MenuItem("Example/ID To Name")] static void Init() { // Get existing open window or if none, make a new one: InstanceIDToObjectExample window = (InstanceIDToObjectExample)EditorWindow.GetWindow(typeof(InstanceIDToObjectExample)); window.Show(); }

void OnGUI() { id = EditorGUILayout.IntField("Instance ID:", id); if (GUILayout.Button("Find Name")) { Object 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); } }

void OnInspectorUpdate() { Repaint(); } }