Using the EventSystem
The EvenSystem consists of the Eventboard and the CallEvent and EventListener node.
The Eventboard is a global scriptable object which contains events including their parameters.
The CallEvent node simply calls a selected event from the assigned Eventboard.
The EventListener node listens to a selected event which has been called by the CallEvent node. If it has been called it will execute the next connected node. EventListeners can be set to listen to local events only. Which means, that it only listens to events called inside of the same graph.
Create an Eventboard and Events
To create event you will need to create an Eventboard first.
- 1.Right click in the projects view and select Create / FlowReactor / New Eventboard.
- 2.Select the newly created eventboard and add your first event called “Say Hello”.
Assign the Eventboard
We now have to assign the Eventboard to our Graph.
- 1.Goto the properties view and select Events. You can now drag and drop the Eventboard asset file to the inspector. Events can now be called by using the CallEvent node.
Each event can have custom parameters. Inside of the Eventboard you can define parameters for each event. It is important to know that you are not assigning any parameter values in the Eventboard, you are only building the parameter “template”. Parameter values or arguments can be assigned in the CallEvent node when calling an actual event.
For our example lets add a string parameter to our “Say Hello” event.
- 1.Click on add parameter and select string.
- 2.Name it: Message
parameter values/arguments are assigned on the CallEvent node only. EventListener node on the other hand are retrieving the parameter values/arguments coming from the event.
Let’s call our event with the custom parameter.
- 1.Create an OnStart node
- 2.Connect the OnStart node with a CallEvent node
- 3.Select the CallEvent node. You can now see all available events in the node inspector, select the “Say Hello” event.
- 4.Assign a text to the event parameter which you want to pass to. For example: “Hello”
Now we need to add an EventListener node to actually listen to our event.
- 1.Add an EventListener node
- 2.Select the event “Say Hello” from the node inspector.
- 3.We now have to store the incoming event parameter value – which is the string variable: Message – to a global blackboard variable. So make sure you have created and assigned a blackboard to your graph with a string variable.
- 4.Now you can “connect” the event parameter “Message” to the blackboard string variable.
- 5.To see if our event gets called and if our event listen node is reacting to it. Connect a Debug.Log node to the EventListener node.
- 6.Connect the “Log” variable from the Debug.Log with the Blackboard variable.
- 7.Assign your graph to a FlowReactorComponent in the scene. Run the scene and you should see the debug.log output: “Hello” in the Unity console.
An EventListener node can also listen to local events only which are called inside of the same graph.
You can inspect all connected CallEvent and EventListener nodes for each event. Simply click on “Connected Nodes”. If the node exists in the current graph you can quickly navigate to it.