UE5 Behavior Tree AI: patrol, spot, chase
By the Cosindra team · Updated August 7, 2026
A behavior tree is how an Unreal Engine enemy decides what to do next. It is not a state machine and it does not run top-to-bottom every frame — misunderstanding those two things is why most first behavior trees look like they are ignoring the player.
This guide covers the parts you have to get right (composites, the blackboard, decorators, services, and the abort setting nobody mentions), then shows the editor calls that build a working patrol → spot → chase enemy.
Selector vs Sequence — the one that trips everyone
A behavior tree has exactly two composite nodes worth memorising, and they are opposites. A Selector runs its children left to right until one SUCCEEDS, then stops. It is "try this, otherwise try that" — the fallback node. A Sequence runs its children left to right until one FAILS. It is "do all of these, in order" — the checklist node.
An enemy brain is usually a Selector at the root with two Sequence branches underneath: a combat branch on the left and a patrol branch on the right. The Selector tries combat first; combat fails when there is no target, so it falls through to patrol. Getting this backwards — a Sequence at the root — produces an enemy that stops permanently the first time anything fails.
The blackboard is the tree’s memory
Behavior tree nodes do not talk to each other directly. They read and write a blackboard: a typed key-value store attached to the tree. "Do I have a target?" is a blackboard key of type Object. "Where am I patrolling to?" is a key of type Vector.
Keys are typed on purpose, and the type decides what can read them. A Move To task accepts a Vector or an Object key; a Blackboard decorator can test Is Set, Is Not Set, or compare a value. Declare the keys before you build the branches, because every decorator and task you add afterwards has to point at one.
Decorators are conditions, services are background work
A decorator attaches to a node and gates it: the node only runs while the decorator passes. A Blackboard decorator checking "TargetActor Is Set" on the combat branch is what makes the Selector fall through to patrol when nothing has been spotted.
A service attaches to a composite and runs on an interval while that branch is active. Services are where you put the "keep looking around" work — refreshing a blackboard key every half second — rather than putting it in a task that has to finish.
Observer Aborts: why your AI never changes its mind
Unreal’s behavior tree is event-driven. It does not re-run from the root every frame — once it is inside the patrol branch, it stays there until that branch finishes. So a decorator that starts passing halfway through a Wait task changes nothing, and the enemy calmly finishes its patrol while the player stands in front of it.
The fix is the decorator’s Observer Aborts setting. "Self" aborts the branch the decorator is on when its result changes. "Lower Priority" aborts anything to the right of it. For a combat branch that must interrupt patrolling the moment a target appears, you want Both. If your AI only reacts between actions, this setting is almost always the reason.
The editor calls that build it
Each row is a tool the assistant runs against your open editor. The order matters — keys before the decorators that read them, composites before the tasks that hang off them.
| # | Tool | What it does |
|---|---|---|
| 1 | create_behavior_tree | Creates the Behavior Tree asset and its paired Blackboard |
| 2 | set_bt_blackboard_key | Declares the typed keys — TargetActor (Object), PatrolPoint (Vector) |
| 3 | add_bt_composite | Root Selector, then a Sequence for combat and one for patrol |
| 4 | add_bt_decorator | Blackboard condition on the combat branch, with Observer Aborts |
| 5 | add_bt_service | Interval service that keeps the target key current |
| 6 | add_bt_task | The leaves — Move To, Wait, and your own task nodes |
| 7 | assign_behavior_tree | Points the AI Controller at the finished tree |
| 8 | get_behavior_tree_info | Reads the assembled structure back so you can check it |
What you end up with
- A Behavior Tree asset and matching Blackboard in your Content folder, openable and editable by hand like any other
- A root Selector with combat and patrol branches, the decorator and abort setting already configured
- An AI Controller wired to run the tree, so a placed enemy behaves immediately in PIE
- Nothing proprietary — these are ordinary UE assets, and the plugin can be uninstalled without touching them
The mistake to watch for
The most common failure is not a broken tree, it is a tree that never re-evaluates: the decorator is correct, the blackboard key is being set, and the enemy still finishes its patrol loop before reacting. Check Observer Aborts before you check anything else.
Second most common: the decorator is on the task instead of the branch. Gating a single Move To leaves the rest of the sequence running when the condition fails. Put the condition on the Sequence that owns the behaviour, not on one node inside it.
Put an AI copilot inside your editor
The free Cosindra desktop app connects to your UE 5.7/5.8 project — the assistant works in your open editor, and what you generate with the web tools applies straight into it. Windows & macOS.
Download CosindraFrequently asked questions
Should the root of a behavior tree be a Selector or a Sequence?
A Selector, almost always. The root has to keep trying alternatives — combat, then investigate, then patrol — and a Selector is the node that falls through on failure. A Sequence at the root means the whole tree stops the first time any child fails, which for an enemy usually means it stops for good the moment there is no target to chase.
What does Observer Aborts do in a Blackboard decorator?
It tells the tree to interrupt work in progress when the decorator’s result flips, instead of waiting for the current branch to finish. Self aborts the branch the decorator sits on; Lower Priority aborts everything to its right; Both does both. Unreal’s behavior tree is event-driven and does not re-tick from the root, so without this an enemy will finish its current Wait or Move To before noticing the player. If your AI reacts a few seconds late, this is the setting.
Do I need C++ to write behavior tree tasks in UE5?
No. Blueprint task, service and decorator classes exist (BTTask_BlueprintBase and friends) and are enough for patrol, chase, attack and most gameplay logic. C++ is worth it for tasks that run every frame on many agents, where the Blueprint overhead per tick starts to show, but that is an optimisation you make after the behaviour works, not a prerequisite.