Events let a tree react to a notification from another task or script. Send Event publishes a named event; Has Received Event returns Success after receiving a matching notification.
Send and receive in the editor
For a non-global event, the event target is the BehaviorTree component. Target Game Object identifies the GameObject containing that component; each task resolves the component before sending or registering.
Leave Target Game Object unassigned to use the current tree. To target another tree, select its GameObject and, when necessary, its Tree Index. When sending from code, pass the corresponding BehaviorTree component to EventHandler.
- Give Send Event and Has Received Event the same nonempty Event Name.
- Leave the target unassigned on both tasks for same-tree communication. For a cross-tree notification, make both tasks resolve to the receiving tree. For example, a commander can send to another AI, or a monitoring tree can listen to another tree’s events.
- Match the argument count and types. Sending an integer requires an integer Shared Variable in the receiver’s stored-value field.
- Configure Conditional Aborts so Has Received Event is reevaluated while another branch runs.
Enable Global Event on both tasks only when the notification should have no tree-specific target. Distinct BehaviorTree components on one GameObject have separate non-global event scopes.

In this example, Has Received Event initially fails and the Selector runs Wait. After one second, Send Event publishes the notification and Idle keeps the tree active. At the next reevaluation, Has Received Event succeeds. React to an Event shows a complete event-driven tree.
Use events from code
Call this method on a component attached to the intended tree’s GameObject. If the GameObject contains several trees, assign the intended component explicitly instead of using GetComponent:
using Opsive.BehaviorDesigner.Runtime;
using UnityEngine;
using EventHandler = Opsive.Shared.Events.EventHandler;
public class SendTreeEvent : MonoBehaviour
{
[SerializeField] private BehaviorTree m_BehaviorTree;
private void Awake()
{
if (m_BehaviorTree == null) {
m_BehaviorTree = GetComponent<BehaviorTree>();
}
}
public void Send()
{
if (m_BehaviorTree != null) {
EventHandler.ExecuteEvent<int>(m_BehaviorTree, "MyEvent", 5);
}
}
}
Both sides must use the same component instance, event name, argument count, and argument types. EventHandler accepts object because Opsive Shared also supports events outside Behavior Designer; that general API does not change the target used by these tasks or make Shared depend on Behavior Designer.
For a code listener, cache the component used for registration and unregister from that same instance. Assign the receiving tree in the Inspector when listening to another tree:
using Opsive.BehaviorDesigner.Runtime;
using UnityEngine;
using EventHandler = Opsive.Shared.Events.EventHandler;
public class ReceiveTreeEvent : MonoBehaviour
{
[SerializeField] private BehaviorTree m_BehaviorTree;
private BehaviorTree m_ListenedTree;
private void OnEnable()
{
m_ListenedTree = m_BehaviorTree != null ? m_BehaviorTree : GetComponent<BehaviorTree>();
if (m_ListenedTree != null) {
EventHandler.RegisterEvent<int>(m_ListenedTree, "MyEvent", ReceivedEvent);
}
}
private void ReceivedEvent(int value)
{
Debug.Log($"Received MyEvent with value {value}", this);
}
private void OnDisable()
{
if (!ReferenceEquals(m_ListenedTree, null)) {
EventHandler.UnregisterEvent<int>(m_ListenedTree, "MyEvent", ReceivedEvent);
m_ListenedTree = null;
}
}
}