Events let a behavior tree respond to a named signal without polling the sender
directly. They are useful for damage, interaction, objective, and animation
notifications that originate outside the active branch.
The original Behavior Designer handles events with the Send Event Action, the Has Received Event Conditional, and the component API. It does not use Event nodes.
Send and receive in a tree
- Add Has Received Event to the branch that should react.
- Give it an event name and, when needed, output variables for the supplied
arguments. - Put the Conditional below a Composite with a suitable
conditional abort so it continues to be
reevaluated while another branch runs. - Add Send Event to the sending tree, enter the same event name, and select
the target GameObject.
The target GameObject must contain the Behavior Tree that should receive the
event. Send Event returns Failure when no Behavior Tree can be found there.
Event names are case-sensitive, so define them in one place when several
systems share the same contract.
Send an event from code
BehaviorTree.SendEvent supports zero to three arguments. The generic types
must match the registered receiver.
using BehaviorDesigner.Runtime;
using UnityEngine;
public class AlertTree : MonoBehaviour
{
[SerializeField] private BehaviorTree behaviorTree;
public void Alert(int level)
{
behaviorTree.SendEvent<int>("Alert", level);
}
}
Listen outside the tree
Register when the listener becomes active and unregister the same delegate when
it becomes inactive.
using BehaviorDesigner.Runtime;
using UnityEngine;
public class AlertListener : MonoBehaviour
{
[SerializeField] private BehaviorTree behaviorTree;
private void OnEnable()
{
behaviorTree.RegisterEvent<int>("Alert", OnAlert);
}
private void OnDisable()
{
behaviorTree.UnregisterEvent<int>("Alert", OnAlert);
}
private void OnAlert(int level)
{
Debug.Log($"Alert level: {level}");
}
}
Verify the signal
Set a breakpoint on Has Received Event or watch its output variable. After
the sender runs, the Conditional should return Success once and the abort should
move execution into the response branch.
If nothing reacts, check the event-name spelling, target Behavior Tree, argument
count and types, and whether the receiving Conditional is still eligible for
reevaluation.