- Home /
Selecting a newly created empty prefab by an editor script
After creating an empty prefab through an editor script, how can I get the editor script to subsequently select the empty prefab in the asset folder?
I tried this:
var prefab = PrefabUtility.CreateEmptyPrefab("test.prefab");
AssetDatabase.Refresh();
Selection.activeObject = prefab;
But this doesn't select the prefab.
Could you let me know if the following works for you:
Selection.objects = new Object[] { prefab };
// the following line is optional but nice :)
EditorGUIUtility.PingObject(prefab);
Thanks! Selection.objects
works! :D It seems that PingObject
wouldn't work when I'm going to run Selection.objects
. Putting PingObject
before or after the Selection.objects
doesn't ping the object. Remove the Selection.objects
and the ping will appear but the object not selected.
Try the following ins$$anonymous$$d:
EditorInternalUtility.FocusInspectorWindow();
EditorGUIUtility.PingObject(prefab);
Selection.objects = new Object[] { prefab };
It looks like it couldn't resolve EditorInternalUtility
. I tried InternalEditorUtility
ins$$anonymous$$d but it doesn't have the method FocusInspectorWindow
.
EditorInternalUtility
is undocumented but it is working for me in both Unity 3.5.7 and 4.1.2. Obviously you need to have using UnityEditor;
at the top of your script.