Is there a way to create a custom hotkey for the “Select” button in the inspector? I’m often finding that I select something in the hierarchy or scene, and then constantly move all the way to top right to click this, then all the way bottom left to navigate the folder, etc.
Would be very nice if this could be bound to a hotkey, I don’t mind if it requires writing a custom editor script, but I tried searching and couldn’t find any API for doing this.
I haven’t used Unity in a long time, but I think this should be quite trivial. You can use a MenuItem on a static method of an editor script and simply use one of the methods of the PrefabUtility like PrefabUtility.GetCorrespondingObjectFromSource which gives you the prefab object for a given instance.
[MenuItem("GameObject/SelectPrefab %#u")]
static void SelectPrefab()
{
var prefab = PrefabUtility.GetCorrespondingObjectFromSource(Selection.activeObject);
if (prefab != null)
Selection.activeObject = prefab;
}
In this example I gave this menu item the shortcut Ctrl+Shift+U. For more information see the MenuItem documentation.
Note that prefabs can get quite complex nowadays with nested prefabs and prefab variants. Depending on the exact wanted behaviour you may need to use a different method from the PrefabUtility class. Note that some methods return an asset path instead of an actual object reference. You can use AssetDatabase.LoadAssetAtPath to get the actual prefab object from an asset path.
I’m also worried about this problem. Have you found a solution?