unreal-behavior-trees
gamedev-skills/awesome-gamedev-agent-skills
Build NPC AI in Unreal Engine 5 with Behavior Trees, Blackboards, and AIControllers.
What is unreal-behavior-trees?
Implement decision-making for enemy and NPC characters in UE5 using Behavior Trees (BT) and Blackboards (BB). Use this skill when creating or debugging AI behavior assets, structuring composite nodes, writing custom tasks or services, or wiring an AIController to run the tree.
- Structure AI logic with Selector (priority/fallback) and Sequence (do-all) composite nodes
- Gate branches with Decorators that read Blackboard keys and support Observer Aborts for reactive re-evaluation
- Keep Blackboard state current with Services that tick periodically while a branch is active
- Write custom BTTask and BTService nodes that return Succeeded, Failed, or InProgress
- Run the tree from an AAIController and update Blackboard keys from C++ code
- Debug live behavior with the Behavior Tree debugger showing active nodes and Blackboard values
How to install unreal-behavior-trees
npx skills add https://github.com/gamedev-skills/awesome-gamedev-agent-skills --skill unreal-behavior-trees- Unreal Engine 5.8 or later
- Basic familiarity with AIController and pawn possession
- A level with a NavMesh Bounds Volume (required for MoveTo tasks)
How to use unreal-behavior-trees
- 1.Create a Blackboard asset (BB_) with typed keys representing the AI's memory (TargetActor, LastKnownLocation, etc.)
- 2.Create a Behavior Tree asset (BT_) and reference the Blackboard
- 3.Structure the tree root with a Selector or Sequence composite, adding child branches for different behaviors
- 4.Add Decorators to gate branches (e.g., 'TargetActor Is Set') and set Observer Aborts to Self/Lower Priority/Both for reactivity
- 5.Attach Services to branches to periodically update Blackboard keys (e.g., sight checks)
- 6.Create an AIController subclass that calls RunBehaviorTree(BehaviorTree) in OnPossess
- 7.Update Blackboard keys from C++ code (e.g., SetTarget) to drive tree decisions
- 8.Use the Behavior Tree debugger during PIE to verify which nodes execute and inspect live Blackboard state
Use cases
- Building a priority-based enemy AI that switches from combat to investigation to patrol based on target detection
- Creating a custom BTTask node for a specific enemy ability or behavior (e.g., flanking, taking cover)
- Setting up reactive AI that interrupts lower-priority branches when a Blackboard key changes (e.g., player spotted)
- Implementing NPC routines with Services that periodically update perception or state while patrolling
- Debugging AI behavior during play-in-editor by inspecting which tree node is executing and Blackboard values
- Unreal Engine 5 gameplay programmers building enemy or NPC AI
- Game designers structuring AI decision trees in the editor
- Developers migrating from FSMs or other AI patterns to Behavior Trees
- Teams using UE 5.8+ with existing BT_/BB_ assets
unreal-behavior-trees FAQ
Both ship in UE 5.8. Use Behavior Trees if the project already has BT_/BB_ assets or the AI is naturally a priority-based fallback chain (attack, else chase, else patrol). Use StateTree if the AI is a set of explicit modes with clear transitions (patrol → alert → combat), or if the team prefers a general-purpose hierarchical state machine.
Check that the pawn is possessed by the AIController (set Auto Possess AI to 'Placed in World or Spawned' and assign the controller), and that RunBehaviorTree was called in OnPossess. Verify the Behavior Tree asset is assigned and the Blackboard reference is set.
The gating Decorator's Observer Aborts is set to None. Change it to Self, Lower Priority, or Both so the tree re-evaluates when the key changes. This is what makes the AI feel reactive.
Call GetBlackboardComponent()->SetValueAsObject(TEXT("KeyName"), Value) from the AIController. Ensure the key name and type match the Blackboard asset exactly, or use a cached FBlackboardKeySelector to avoid typos.
Sequence runs children left-to-right until one fails (AND logic: do all steps). Selector runs children until one succeeds (OR logic: try each option in priority order). Swapping them inverts the behavior.
Full instructions (SKILL.md)
Source of truth, from gamedev-skills/awesome-gamedev-agent-skills.
name: unreal-behavior-trees description: > Build NPC AI in Unreal Engine 5 with Behavior Trees and Blackboards: composites (Selector/Sequence), tasks, decorators, services, and running the tree from an AIController. Use when creating enemy/NPC AI, BT_/BB_ assets, custom BTTask or BTService nodes, or when the user mentions Behavior Tree, Blackboard, AIController, BTTask, decorator, or service.
Unreal Behavior Trees
Author NPC decision-making in UE5 with Behavior Trees driven by a Blackboard: structure the tree with composites, gate branches with decorators, keep state current with services, and run it from an AIController. Targets UE 5.8.
When to use
- Use when building enemy/NPC AI: creating a
BT_/BB_asset pair, structuring Selector/Sequence branches, adding decorators (conditions) and services (periodic updates), writing customBTTask/BTServicenodes, or wiring an AIController to run the tree. - Use when the project has Behavior Tree (
BT_) and Blackboard (BB_) assets and anAAIController.
When not to use: the concept of AI (FSM vs BT vs steering, cross-engine) →
game-ai. Pure navigation/pathing math is engine navmesh (BT's MoveTo uses it). Simple
one-off logic may be cheaper as a small state machine than a full tree.
Behavior Tree or StateTree? UE 5.8 ships both, and Behavior Trees are not deprecated.
StateTree is Epic's general-purpose hierarchical state machine: it combines BT-style
selection with explicit States and Transitions. If the project already uses StateTree
assets, or the AI is naturally a set of modes with clear transitions (patrol → alert →
combat), check with the user before adding a Behavior Tree next to it. Keep using Behavior
Trees where the project already has BT_/BB_ assets.
Core workflow
- Create the pair: a Blackboard (
BB_) holds typed keys (the AI's memory:TargetActor,LastKnownLocation,bIsInvestigating); a Behavior Tree (BT_) references that Blackboard. - Possess and run. An
AAIControllerpossesses the pawn and callsRunBehaviorTree(BT), which also initializes the referenced Blackboard. - Structure with composites. Selector runs children left→right until one succeeds (priority/fallback: "attack, else chase, else patrol"). Sequence runs children until one fails (do-all: "move to cover → reload → peek"). Simple Parallel runs one main task alongside a secondary.
- Gate branches with Decorators that read Blackboard keys (e.g. "Has Target?" guards the combat branch). Set Observer Aborts so the tree re-evaluates when the key changes.
- Keep the Blackboard current with Services attached to a branch — they tick periodically
(e.g. update
TargetActorvia a sight check) only while that branch is active. - Do work in Tasks, which return
Succeeded,Failed, orInProgress(latent tasks likeMoveTofinish later). - Verify with the Behavior Tree debugger during PIE — it highlights the running node and shows live Blackboard values, so you see exactly which branch executes.
Patterns
1. AIController that runs the tree (C++)
void AEnemyAIController::OnPossess(APawn* InPawn)
{
Super::OnPossess(InPawn);
if (BehaviorTree) // UPROPERTY(EditAnywhere) TObjectPtr<UBehaviorTree>
RunBehaviorTree(BehaviorTree); // initializes & uses the Blackboard the BT references
}
2. A priority tree (node structure)
ROOT
└── Selector (try combat, else investigate, else patrol)
├── Sequence [Decorator: Blackboard 'TargetActor' Is Set, Observer Aborts: Both]
│ ├── Task: MoveTo (TargetActor) // latent: returns InProgress then Succeeded
│ └── Task: Attack
├── Sequence [Decorator: 'LastKnownLocation' Is Set]
│ ├── Task: MoveTo (LastKnownLocation)
│ └── Task: Wait (3s) + clear key
└── Task: Patrol (BTTask_FindPatrolPoint -> MoveTo)
Observer Aborts: Both makes the combat branch interrupt patrol the instant TargetActor is
set, and bail out when it's cleared — this is what makes the AI feel reactive.
3. Updating the Blackboard from code (e.g. on seeing the player)
void AEnemyAIController::SetTarget(AActor* Target)
{
if (UBlackboardComponent* BB = GetBlackboardComponent())
BB->SetValueAsObject(TEXT("TargetActor"), Target); // key name must match the BB asset
}
// Clear with BB->ClearValue(TEXT("TargetActor")); to drop back to a lower-priority branch.
Pitfalls
- AI never starts — the pawn isn't possessed (set the Pawn's Auto Possess AI to "Placed
in World or Spawned" and assign the AIController), or
RunBehaviorTreewas never called. MoveToinstantly fails — no NavMesh in the level (add a Nav Mesh Bounds Volume), or the target is off the navmesh.- Branch doesn't react to changes — the gating Decorator's Observer Aborts is set to None; set it to Self/Lower Priority/Both so the tree re-evaluates when the key changes.
- A task hangs the tree — a custom task returned
InProgressand never callsFinishLatentTask. Always complete latent tasks. - Blackboard key typos —
SetValueAsObject("Taget", ...)silently does nothing; match the key name and type exactly, or use a cachedFBlackboardKeySelector. - Sequence vs Selector confusion — Sequence = AND (stops on first failure); Selector = OR (stops on first success). Swapping them inverts the behaviour.
References
- For a custom C++
UBTTaskNode(instant and latentExecuteTaskreturningEBTNodeResult, with aFBlackboardKeySelector), readreferences/custom-bttask.md. - Primary docs: "Behavior Trees in Unreal Engine"
(
https://dev.epicgames.com/documentation/en-us/unreal-engine/behavior-trees-in-unreal-engine).
Related skills
game-ai— engine-agnostic AI design (FSM, BT, steering, pathfinding choices).unreal-cpp-gameplay— the AIController and pawn classes in C++.fps-shooter/tower-defense— genres that compose enemy AI.
Related skills
More from gamedev-skills/awesome-gamedev-agent-skills and the wider catalog.

unreal-blueprints
Build Unreal Engine 5 gameplay with Blueprint visual scripting—events, variables, and decoupled communication.

unreal-cpp-gameplay
Write Unreal Engine 5 C++ gameplay classes with reflection macros, Gameplay Framework, and module dependencies.

unreal-enhanced-input
Set up player input in Unreal Engine 5 with Enhanced Input system: Input Actions, Mapping Contexts, modifiers, and triggers.

unreal-niagara
Create and control real-time particle effects in Unreal Engine 5 with Niagara systems, emitters, and modules.

unreal-packaging
Package and ship UE5 projects with editor menus or command-line BuildCookRun automation.

visual-novel
Build branching visual novels with script engine, character display, choices, and player conveniences like save/load and skip.