by Jon (Updated on 2014-01-26)
- What are Custom Events?
- Defining Custom Events
- Triggering Custom Events
- One Recipient vs. All
- Making the Custom Event Configurable
- Custom Events vs. Custom Blocks
What are Custom Events?
Custom Events are special kinds of events that happen only when you tell them to happen.
Why would you want to do this?
- Reuse Logic. If you're finding that you're copying and pasting the same code, you could stick it into a Custom Event and trigger that Custom Event instead.
Allow other behaviors to cause stuff to happen
Defining Custom Events
1) Inside the Behavior Designer, go to Add Event > Advanced > Custom Event
2) Type something into the blank. This is the text that will cause this Custom Event to trigger.
That's it! Now fill out what you want to happen inside the event.
Triggering Custom Events
Custom Events are triggered by any one of the blocks under Behavior > Triggers. The act of telling a Custom Event to happen is called triggering.
To trigger an event, put in the text you stuck into the blank when defining the event.
That's all there is to triggering Custom Events.
You might be curious about what the difference is between the "all behaviors" vs. "(one) behavior" variants though...
One Recipient vs. All
As you have may noticed, triggering Custom Events can be done directly (one behavior) or indirectly (all behaviors). This to say:
You can specify exactly which behavior you're targeting.
You specify no target, so it attempts to trigger the event for all behaviors for a particular Actor or Scene.
When would specifying no target ("all behaviors") be useful?
- A bunch of behaviors happen to receive the same event, and you want to target them all at once.
- You don't feel like typing in the target behavior, so you target them all. Besides a minor performance penalty, there's nothing wrong with this.
Making the Custom Event Configurable
In some rare instances, you may find a need to make a Custom Event configurable. Which is say that you want to stick a Text Attribute into the blank.
You can do this, and as you'd expect, the text for Custom Event becomes configurable.
Custom Events vs. Custom Blocks
Custom Events and Custom Blocks overlap somewhat in use case. Custom Events differ from Custom Blocks in one key area: they don't accept "parameters." If you need to pass some data in, you have to use a Custom Block instead.
- Custom Events are events that you trigger yourself.
- You define the text that triggers the event.
- Generally speaking, it's easier and simpler to just target all behaviors rather than specifying a specific recipient.