Note |
---|
To use Bolt, which is Unity’s visual scripting solution, you must purchase it on the Unity Asset Store. |
Super Units are flow graphs that are nested in a parent flow graph as a single unit. They are a powerful feature that allows you to re-use and organize your flow graphs.
For this example, we’ll create a Take Damage super unit. Its task will be to substract the input damage from the health object variable, then check if it is below zero, in which case it should play a death animation. Then, it should return control to the parent unit and output a boolean that indicates whether the character was killed.
To create a blank super unit, right-click an empty space in your graph
and choose Nesting > Super Unit. The super
unit inspectorA Unity window that displays information about the currently selected GameObject, Asset or Project Settings, alowing you to inspect and edit the values. More info
See in Glossary works exactly like that of a machine; you can switch the
source of the graph between embed and macro and convert if you need.
If you want to give a title and summary to your super unit, you can do so from the graph inspector:
For now, click the Edit Graph button or double-click the node to open the nested graph. Now that you’re in the sub graph, the breadcrumbs at the top left of the graph window allow you to navigate back up:
By default, the embed graphs in super units are created with Input and Output nodes:
These are special nodes allow you to pass flow and values to and from the parent flow graph.
Let’s start with the input. Click on the input node to open it in the graph inspector. For our Take Damage unit, we will need two inputs:
We will give the damage input a default value of 5 and hide the label for the entry point, because what it does can be deduced from context. For the moment, we won’t spend time customizing the label and summary of each port, but keep in mind that you can use those to document your own super units.
As we go, the input node will get updated. When you’re done, it should look like this:
Now, let’s configure the output. Click on the output node to open it in the graph inspector. For our unit, we will need two outputs:
When you’re done, the output node should look like this:
Here are some very important constraints to keep in mind while defining inputs and outputs:
Bolt will warn you from the inspector if you do not meet these criteria.
Now that we have our input and output nodes, we only have the hard part left to do! We’ll leave the implementation of this node as a homework and won’t go through it step by step, but here’s what the final result could look like:
Back in the parent graph, all of this complex logic turns into a simple, single unit with 2 inputs and 2 outputs. Tadah!
If you have a flow macro that you want to use as a super unit, you can either drag & drop it into your graph, or create it from the Macros category in the fuzzy finder.
If you want to share your super unit with others, simply convert it to a macro and upload it. Since macros are just normal asset files, you can share them with your team and your friends!
You can also share the macro in the #library channel on the Bolt Discord server.
Note: Stay tuned! We’re currently working on better ways to share your graphs.