Class AIBrainComponent
The coordinating MonoBehaviour that bridges the Panda Behaviour Tree, the traffic system, and the path-follow system for an autonomous AI actor.
[RequireComponent(typeof(PandaBehaviour))]
public class AIBrainComponent : MonoBehaviour
Inheritance
Examples
The .panda script below mirrors the real PathFollowTree.BT.txt structure.
The IsSleeping condition keeps the actor stopped until an AIActivationEvent
fires; once the event triggers, OnEventActivate sets IsSleeping = false and
the PathFollow sub-tree becomes reachable. The _linkedEvent field on
AIBrainComponent must reference the matching AIActivationEvent
asset in the Inspector for this wiring to take effect.
// PathFollowTree.BT — assign to the PandaBehaviour component on the AI actor.
tree("AI Controlled")
fallback
tree("Event Linked") // blocks movement until the activation event fires
tree("PathFollow") // normal autonomous path-following loop
// IsSleeping is true from OnEventInit until the linked AIActivationEvent fires.
// While sleeping, StopMovement() is called each tick so the actor does not drift.
tree("Event Linked")
sequence
IsSleeping // [Task] bool — succeeds while dormant, fails once awake
StopMovement()
Wait(0.1)
// HasDestination() / MoveToDestinatoin() / UpdateTrafficProcess() are all [Task]
// methods on AIBrainComponent; UpdateTrafficProcess manually drives the traffic
// component because SetController(this) suppresses its own Update loop.
tree("PathFollow")
fallback
sequence
HasDestination()
UpdateWaypoint()
MoveToDestinatoin()
UpdateTrafficProcess()
sequence
StopMovement()
Wait(0.1)
Remarks
Each AI actor has a Panda BT script (a .panda asset) that describes its behaviour in
a tree of tasks. The BT calls methods on this component — the methods marked [Task]
are the leaf nodes that the BT can invoke, check, or await. The brain is therefore the
adapter layer between the declarative BT description and the imperative C# systems
(pathfinding, traffic, event responses).
Traffic updates are normally driven by Update each frame. When
the AI brain is active, it calls Object) to "hijack"
the traffic component so the BT can decide when to call DoUpdate
(via the UpdateTrafficProcess task) rather than letting it run unconditionally each frame.
This gives the BT control over whether traffic avoidance is applied at any given step.
The optional _linkedEvent allows a specific trigger in the scene to activate
the actor. When the event fires, IsSleeping is set to false and the BT begins
executing; before the event fires the actor remains dormant.
Properties
IsEventLinked
Checks if there is an event linked to this compoonent, and if said event is active in the scene.
public bool IsEventLinked { get; }
Property Value
bool
Methods
LinkEvent(AIActivationEvent)
Subscrible the actions to the specified event's OnInitialize and OnTrigger.
public bool LinkEvent(AIActivationEvent linkedEvent)
Parameters
| Name | Type | Description |
|---|---|---|
linkedEvent | AIActivationEvent | The event to be linked. |
Returns
bool — True if the event is successfully linked, false otherwise.
UnlinkEvent(AIActivationEvent)
Unsubscrible the actions from the specified event.
public bool UnlinkEvent(AIActivationEvent linkedEvent)
Parameters
| Name | Type | Description |
|---|---|---|
linkedEvent | AIActivationEvent | The event to be unlinked. |
Returns
bool — True if the event is successfully unlinked, false otherwise.