0
Answered

Trigger Custom Event

JPAC 3 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 5

Hi,

I want to trigger a "Custom Event" from code for a transition.  What's the API to do that?  I can't seem to figure it out.

Thanks!


Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):

Answer

+1
Answer
Answered

Hi JPAC,

As others pointed out, using CustomEvent.Trigger is the right approach.

I will soon add a basic scripting interaction section to the manual that will cover it in more details, but let me know if you have questions about its use here in the mean time.

Looks like it is Bolt.CustomEvent.Trigger(), has 7 different overloads.

Thats what I've been using, works fine!

Typical use: CustomEvent.Trigger(objectToBroadcastTo, "nameOfEvent");

+1
Answer
Answered

Hi JPAC,

As others pointed out, using CustomEvent.Trigger is the right approach.

I will soon add a basic scripting interaction section to the manual that will cover it in more details, but let me know if you have questions about its use here in the mean time.

Can you give as a small example?
Every workaround i builded till now feels like to over complicate things.

+4

Sure!

Let's say you have a game object called Test in your scene with the following graph:


In scripting, you could use the following line to call the Example event with the first argument as "Hello!":

var test = GameObject.Find("Test");
CustomEvent.Trigger(test, "Example", "Hello!");

This will then log "Message is: Hello!" to the console.