Events

 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: 


Custom Events

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.

Animation Events

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.

Unity Events

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.

This article was helpful for 10 people. Is this article helpful for you?

+1

Health should be A and OnDamage B

Is "Get gameObject" supposed to be causing an argument mismatch in the below flow? I'm trying to trigger a custom event after confirming what kind of object I've collided with. Each instance of "Objective" sends this event to the ObjectiveSystem gameObject along with a reference to itself as an argument (because the Objective System will subsequently remove this Objective from a list of objectives). Unclear how I'm passing 2 arguments to the custom event trigger block.



Does the receiver for Objective F take 1 argument too?

+1

Which version of Bolt are you using? This was a bug in previous versions that has been fixed since then. Since your nodes don't scale according to content, I presume you're on an older version with this bug.

Bingo! I was not on the latest on that machine, now updated to 1.1.3

is the OnEnabled event called before the Start event? i.e., is it actually the Awake event? i was searching for the Awake event but couldn't find it. EDIT: just ran a quick test. OnEnabled appears to fire before Start.

More of a Unity question than a Bolt one, here's the answer though. And of course if the script is Disabled (unchecked in the inspector) then OnEnabled is irrelevant to the order of Awake/Start, only is that Event triggered when the component is enabled.

wow! very helpful. thanks. i think i didn't find it because i searched the Unity doc on "OnEnabled" instead of "OnEnable."

however, i still cannot find any "Awake" event unit in Bolt. is there one?

EDIT: or perhaps there is no need for one, since it seems to be the place to initialize variables, which Bolt does well on its own?

+4

There is no Awake event in Bolt, because it needs to "reserve" it for internal things (like initializing the graph and variables, yes). You can use OnEnable if you need an event that happens before Start (as long as your machine is enabled).

+3

I'm working on a tutorial, but I can not get out of it anymore.  because, I can not find the Time item in the events. I need On Timer Elapsed, but I can not find it.

주석아 나 찾았다

 time 에서 cooldown이 같은역할이다

따봉부탁한다

Is it possible to spread an event to more than one receiver?
For example in the Video Tutorials the Key does the UI Icon Change...
But would it be possible to somehow Trigger an event without a target to notify all FlowMachines?
This way the UI FlowMachine could do it without the key caring about UI stuff...

From this article I came to know about the life cycle of the events that was going to happen this month it was just amazing to know that. I want to buy this but first I want to read reviews that was about that I got from australianwritings review this has all reviews about the famous websites of this city with rating wise.

Is there a way to use custom events in a more type-safe way?

I was thinking in the same way variables are created, but to also be able to create “events” variables. The idea is to have a place where to see a list of them and maybe have a drop down to select which one at the time of triggering one (that dropdown could work for Get Variable too by the way).

Or also maybe a middle man, an scriptable object “event” that works as the name (and could contain a payload and different settings such as broadcast)? (Just started with Bolt and I’m going through the documentation, excuse me if this is probably doable already)

Update to my previous message: a new macro node that hard codes the name would do the trick. Instead of using a trigger custom event node, we would use a TriggerOnDamage user created node.