Note |
---|
To use Bolt, which is Unity’s visual scripting solution, you must purchase it on the Unity Asset Store. |
Transitions are what connect states to determine when the active state should switch.
To create a transition, right-click the source state and select Make Transition. Then, click on the destination state.
You can also end the transition at an empty space in the graph to create a new state automatically:
As a shortcut, you can hold Ctrl (Cmd on Mac) on the source node and drag to create a transition.
Just like flow states, a transition is also… a nested flow graph!
As you can see in the graph 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, there are a few problems with our
new transition. It is never traversed because we never provided an event
specifying when to branch. This is why the transition, along with the
destination state, are both dimmed out.
If you double-click its node or click the Edit Graph button, you will dig into the transition’s graph. By default, it is configured like this:
The Trigger State Transition unit is a special unit that tells the parent state it should branch via the current transition. You can use any unit in a state transition graph, like events or branches.
For example, if we want to transition to the chase state only when an object with the Player tag enters the trigger on the enemy, we could have a transition graph that looks like this:
Finally, if we want to customize the label our transition will have in the parent state graph, we can deselect all units and edit the graph’s title in the graph inspector:
When we go back to the parent state, our transition looks like so:
If you don’t assign a custom title for your transition, the name and description of the event will be used.
By default, transition labels are always visible. If you find this takes up too much screen real-estate in your graph, you can change their display trigger under Preferences > Bolt > State Graphs > Transitions Reveal.
Sometimes, it might be useful for a state to transition to itself. To do so, right-click the state and choose Make Self Transition.
For example, imagine you want an enemy to patrol by changing its destination to a random position every 3 seconds.
Your patrol state’s flow graph could be:
And your self-transition’s flow graph could be:
In the parent state graph, it would look like:
There is no limit to how many transitions can be added to a state. However, there is no notion of priority between transitions. You have to use conditions to make sure the right transition gets chosen.