Events are triggers that you can listen to in order to do something when they happen. They are the starting point for all the Flow and show up as special green nodes in graphs.
There are many kinds of events to choose from, grouped in sub-categories under the root Events category:
Two simple common events are Start and Update, both located under Lifecycle.
- Start gets called once when the graph or event handler is first created.
- Update gets called at every frame while the graph or event handler is active.
New flow machines start with both these events by default. :
Inputs & Outputs
All events have a single Trigger control output that starts the flow when they are triggered.
When events have value inputs, these are options that influence when the event will get triggered. For example, on the On Timer Elapsed event, the number of seconds during which to wait is an event setting. Some events have a Target setting that determines which object is listening to the event. Most often, you'll leave this setting at its default value of Self.
The value outputs on events are arguments that are passed from the event, giving you more information about what actually happened. For example, on the On Trigger Enter event, the other collider that was involved in the collision is an output:
There is a special type of event, the Custom Event, that you can use to trigger your very own events across graphs, along with their custom arguments.
Let's say we wanted create a custom event called On Damage that should get called to make the character lose health. This event should have one integer argument that indicates the amount of damage to inflict.
First, we can listen to the event by creating a Custom Event unit (under Events). We will set its name to On Damage. The field below the name is the argument count, which we will set to 1.
Note that as always, indices are zero-based, so the first argument is labeled Arg. 0.
To trigger the event from elsewhere, we must use the Trigger Custom Event unit, located right under the Custom Event unit in the fuzzy finder. We will configure it the same way, like a mirror. Make sure to type the name of the event in the exact same way, because it is sensitive to case and whitespace.
For example, if you were creating a flow machine on a boulder that could hit the player, you might want to use the force of the impact as the damage. Your trigger graph would therefore look something like this:
Notice we are using the collider that hit with the boulder as the target of our trigger. This means the On Damage event will be triggered on all machines attached to that collider.
Finally, you could use the damage value to subtract health from the receiver object, for example:
Custom events do not require a receiver and will not cause an error if there is no listener to handle them.
You can use animation events to trigger Bolt graphs when you reach a certain point in your animation.
First, select an object with a machine and an animator. Then, from the animation window, add an animation event:
With the event selected, choose TriggerAnimationEvent as the function from the inspector:
You can use any parameter you wish from the inspector:
Then, in your flow graph, add an Animation Event unit (under Events > Animation).
There are two types: a global animation event, and a named animation event.
The difference between them is that the first one will listen to all animation events on the object and return the string parameter.
The second one will only trigger is the string parameter is equal to the specified name input.
You can use Unity Events to trigger events that have been setup from the inspector.
These are commonly found in GUI components like buttons, but they can also be created in your custom scripts. In the inspector, they look like this:
You can configure them by selecting an object with a machine and choosing the Trigger Unity Event method. In the string field, type the event name you wish to listen to in your graph.
Finally, in your graph, just add a UnityEvent unit with a matching name:
Additional arguments are not supported on Unity events.
Customer support service by UserEcho