Object Reference Drawer

  05. Enhanced Drawers No Comments

The drawer forĀ Unity Object reference fields in Power Inspector has been enhanced with addition features.

The Drag N Drop Conundrum

A common problem in the default inspector occurs, when you want to assign a reference to a Component field, but the Component resides on a different GameObject.

How do you do that exactly?

If you try to drag-n-drop the target GameObject from the hierarchy view, it always just assigns its Transform Component.

The Object Picker is no help here either, as it can’t be used to select a specific Component inside a GameObject.

The only way to get around this problem in the default inspector is through an obscure and lengthy process involving the opening of multiple inspector windows and the locking of views. I suspect it’s something that many users don’t even know how to do.

Cross-GameObject Drag-N-Drop

In Power Inspector, if you drag a GameObject reference from the hierarchy view to a Component field, the quick select context menu pops open, letting you specify exactly which Component you wish to assign.

(If you do the same with an Unity Object field, the same thing happens, except this time the dragged GameObject is also listed as an additional option.)

Quick Select Context Menu

You can also manually open the quick select context menu by right-clicking the object reference control.
When opened in this manner, the menu will list all valid targets within the open Scenes.

All options will be hierarchically organized in the same order as they appear in the Hierarchy view, providing a fast and intuitive method for locating your target.

Flexible Copy-Paste

You can copy-paste values between Object reference class members in Power Inspector, just like you would with other fields.

In addition to this, you can paste references to the Object reference drawer from the following sources:

  1. References copied from GameObject, Component and asset headers in Power Inspector.
  2. References copied from the Hierarchy view.
  3. References copied from the Project view.
  4. Asset paths in the clipboard (for example via the “Copy Path” context menu item)

Note: Pasting reference from the Hierarchy and Project views works only when copied using the “Edit/Copy” menu item or with the keyboard shortcut Ctrl+C (Cmd+C on macOS). References copied using the context menu won’t work.