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.
Creating a Behavior Tree and Blackboard
Section titled “Creating a Behavior Tree and Blackboard”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
Blackboard keys
Section titled “Blackboard keys”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.
Composite nodes
Section titled “Composite nodes”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).
Task nodes
Section titled “Task nodes”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.
Decorators
Section titled “Decorators”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.
Services
Section titled “Services”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.
Setting properties
Section titled “Setting properties”Set the AcceptableRadius on the MoveTo task to 50 Set the BlackboardKey on the decorator to TargetActor
Declarative spec
Section titled “Declarative spec”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.