Skip to content

Behavior Trees

Behavior Trees are UE’s built-in AI decision system. BlueprintAI can create trees and blackboards, add composite nodes, tasks, decorators, and services, and set their properties.

Create a Behavior Tree called BT_Enemy and a Blackboard called BB_Enemy in /Game/AI

Associate BB_Enemy as the blackboard for BT_Enemy

Add a blackboard key called TargetActor of type Object (Actor) to BB_Enemy Add a key called PatrolIndex of type Int Add a key called IsAlerted of type Bool

Supported key types: Bool, Int, Float, String, Name, Vector, Rotator, Object, Class, Enum.

Add a Selector node as the root of BT_Enemy Add a Sequence node as a child of the root Selector

Composites: Selector (tries children until one succeeds), Sequence (runs children in order until one fails), SimpleParallel (runs two branches concurrently).

Add a BTTask_MoveTo task to the Sequence, targeting the TargetActor blackboard key Add a BTTask_Wait task with a wait time of 2 seconds

You can use built-in tasks or custom UBTTaskNode subclasses from your project.

Add a BTDecorator_Blackboard decorator to the MoveTo task, checking that TargetActor is set Set the decorator’s observer abort to LowerPriority

Decorators act as conditions or observers on nodes. Common ones: BTDecorator_Blackboard, BTDecorator_IsAtLocation, BTDecorator_CooldownGuard, BTDecorator_LoopCount.

Add a BTService_DefaultFocus service to the root Selector with an interval of 0.5 seconds

Services run on a tick while their branch is active. Common ones: BTService_DefaultFocus, BTService_BlackboardBase.

Set the AcceptableRadius on the MoveTo task to 50 Set the BlackboardKey on the decorator to TargetActor

For complex trees you can describe the whole structure at once:

Build a behavior tree for an enemy that: patrols between waypoints when not alerted, chases and attacks the player when alerted, returns to patrol if it loses sight for more than 5 seconds.

The AI uses the declarative spec system to decompose this into a complete tree structure with correct composite types, tasks, decorators, and blackboard keys.