Object references
Last updated
Last updated
It's a common pattern in Unity to reference objects and components from one Prefab to another. A simple example is Cinemachine: to target an object with a camera, you normally assign that object's Transform to the Tracking Target property of a CinemachineCamera
.
But how to do it when the object you want to assign simply isn't visible, because it's a child of a locked Prefab?
This is why you might want to expose an object reference on the BlackBox. When you do so, the reference will be visualised as an ObjectField without the little circular "picker icon":
From here, you can simply right-click on the field and choose Copy, and then paste where you need this reference.
You will notice that trying to change the reference or nulling it shouldn't work, so you can't break the reference involuntarily with an override while you work on the Prefab.
To reveal a reference, you can do it in two ways:
Click on the Show Available Properties and Methods button on the BlackBox, and expand the foldouts until you arrive to the gameObject or component you're interested in.
Object References are preceded by a small [R] letter:
Press the [+] button to add the component or gameObject to the reveal list.
References to components can also be revealed in context. While you have the right GameObject selected, right-click the component's title bar and choose BlackBox > Reference to Component > Reveal in..., like so:
First List, Second List... what are they?
Unfortunately, a Unity limitation means we can't display the custom names that you might have assigned to Reveal lists, and that's why they are displayed as First List, Second List, etc. up to 5 lists.
To add components to a higher number list, you can move the list in one of the first 5 positions, add the component, and move it back (using the reorder buttons in Edit mode).