How to connect prefab GameObjects to prefab macro

nola602 3 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 3

I am trying to make a Prefab with a Flow Graph that manipulates GameObjects within the Prefab.  How do I reference the specific items in the Prefab?  I don't see any way to make the connection.  It works if I add the graph as an Embed, but then it doesn't get saved with the Prefab.

Specifically, I am trying to use a Flow Graph to manipulate a RectTransform in a Canvas Prefab.  I have added a Flow Machine as a Macro, but when I try to connect the RectTransform via a RectTransform Literal node, there is no way to reference the RectTransform in the Prefab.  What I am doing wrong?  I am new to Bolt, so I am probably missing something fundamental.

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):

Hi Nola!

In Unity, assets (like macros) cannot refer to scene objects. What is probably happening is that you're dragging the RectTransform from the instance of the prefab in your current scene, so Bolt stops you because the macro can't know about anything in the scene.

The right approach in this case is to create an Object Variable on the same object that has the macro, and make that variable point to the scene reference (the RectTransform in your case). Then, in the graph, you can drag that variable in to create a Get Variable unit that will return the transform.

So does that mean that I have to manually connect the instance variables for every prefab I add to the scene?  Or is there a way to maintain the reference between the newly instantiated prefab children and the variables needed for the Flow machine?

The Unity prefab override system is pretty smart for this. If you assign a variable to an object within the prefab (when in isolation mode), then instances of that prefab will refer to the corresponding child object within the instance. So no, there shouldn't be manual maintenance involved!