UE5 Behavior Tree AI: patrol, spot, chase
By the Cosindra team · Updated November 1, 2026
A UE5 behavior tree (behaviour tree) takes five steps to set up: create a Blackboard with the keys the enemy needs, create a Behavior Tree that uses it, give the tree a root Selector with a combat Sequence and a patrol Sequence, call Run Behavior Tree from the enemy's AIController on possess, and add a Nav Mesh Bounds Volume so Move To can path. The steps are numbered below, with the settings that make an enemy react on time.
To build enemy AI with a UE5 behavior tree (behaviour tree), you need three things: a Behavior Tree asset that picks the next action, a Blackboard that stores what the AI knows, and an AI Controller that starts the tree with Run Behavior Tree. A root Selector that tries combat first and falls back to patrol is the usual starting shape.
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.
Set up a behavior tree in five steps
- In the Content Browser, right-click and choose Artificial Intelligence, then Blackboard. Add a TargetActor key of type Object (base class Actor) and a PatrolLocation key of type Vector.
- Choose Artificial Intelligence, then Behavior Tree, open it and set its Blackboard Asset to the Blackboard you just made.
- From Root, add a Selector. Under it, add a combat Sequence on the left with a Blackboard decorator (TargetActor Is Set, Observer Aborts set to Both) and a Move To TargetActor task, and a patrol Sequence on the right with Move To PatrolLocation and Wait.
- Create an AIController Blueprint and, on Event On Possess, call Run Behavior Tree with your tree.
- Open the enemy pawn, set AI Controller Class to that controller and Auto Possess AI to Placed in World or Spawned, then drop a Nav Mesh Bounds Volume over the level so Move To has a path.
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.
Frequently asked questions
How do I set up a behavior tree in UE5?
Create a Blackboard with your keys (for example TargetActor and PatrolLocation), create a Behavior Tree that uses it, give it a root Selector with a combat Sequence and a patrol Sequence, and call Run Behavior Tree from the enemy's AIController on Event On Possess. Set the pawn's AI Controller Class to that controller and add a Nav Mesh Bounds Volume so Move To can find a path.
Behavior tree or behaviour tree: is there a difference?
No. Unreal spells it Behavior Tree in the editor; behaviour tree is the British spelling of the same system.
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.
How do I make defending AI in UE5 that guards a point or a base?
Add a Vector key such as DefendLocation to the Blackboard and set it when the AI Controller possesses the pawn. Keep the root Selector: the combat branch runs while TargetActor is set (Observer Aborts set to Both), and a service clears TargetActor when the target or the guard gets too far from DefendLocation, so the guard never chases forever. The fallback branch is a Sequence of Move To DefendLocation and Wait. Move To needs a Nav Mesh Bounds Volume covering the area.
How do I start a behavior tree on an enemy in UE5?
Create an AI Controller Blueprint and call Run Behavior Tree with your tree on Event On Possess (or BeginPlay). Then open the enemy pawn, set AI Controller Class to that controller and Auto Possess AI to Placed in World or Spawned, so both placed and spawned enemies get it. If the tree runs but the enemy does not move, check for a Nav Mesh Bounds Volume first.