Graph Events are a great way to signal the graph that something happened and react accordingly. NodeCanvas has an internal Event system which can be used in any type of graph. Events can also have any type of variable included and thus possible to also communicate variables with them.
As of version 3.x, there is also an alternative way for utilizing graph events called Signals.
You can send an event using the included Action Tasks SendEvent or SendEvent<T> in case it is a value event. When using the SendEvent<T> you will also be able to provide a value for the event to transfer from within the editor inspector. Following is an example of a SendEvent<float>.
You can also send an event easily from code of course. You can do this by having a reference to the GraphOwner. For example.
1 2 3 4 5 6 7 8 9 10 11 12 |
public class Example : MonoBehaviour{ public BehaviourTreeOwner owner; public void SendNormalEvent(){ owner.SendEvent( "MyEvent" ); } public void SendValueEvent(){ owner.SendEvent<float>( "MyEvent", 1.2f ); } } |
To Check for an event in the Graph, you should use the included Condition Task called CheckEvent or CheckEvent<T> in case of a value event.
Using the CheckEvent<T> also allows you to store the received event value to a Blackboard Variable for later usage. The CheckEvent condition will return true for only one frame; Not until the event is consumed.
In regards to FSMs, using events is very straightforward, but using events in Behaviour Trees along with the various Decorators included allows for a lot of flexibility in designing a behaviour tree. For example:
© Paradox Notion 2014-2024. All rights reserved.