unreal-behavior-trees
Skill399 starsChanged 3 months agoMITView on GitHub
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.
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 24
Use when building enemy/NPC AI: creating a BT_/BB_ asset pair, structuring Selector/Sequence branches, adding decorators (conditions) and …
- Very specific: line 27
Use when the project has Behavior Tree (BT_) and Blackboard (BB_) assets and an AAIController.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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.4+.
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.
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.
Other versions3 projects use a version of this.
Word for word · 2
- ukanwat/overtime★ 399100% same
- ukanwat/selfstarter★ 399100% same
Edited · 1
- gamedev-skills/awesome-gamedev-agent-skills★ 6.4k83% same
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository20 other files it gives its agents.
- audio-designSkill
- camera-systemsSkill
- dialogue-systemsSkill
- game-aiSkill
- game-feelSkill
- game-ui-uxSkill
- input-systemsSkill
- level-designSkill
- performance-optimizationSkill
- physics-tuningSkill
- procedural-genSkill
- reference-imagesSkill
- save-systemsSkill
- shader-programmingSkill
- unreal-blueprintsSkill
- unreal-cpp-gameplaySkill
- unreal-enhanced-inputSkill
- unreal-niagaraSkill
- unreal-packagingSkill
- overtime-docsSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

