UE5 Behavior Tree Patrol Basics
In this Unreal Engine 5 tutorial, you will learn how to rebuild a simple enemy patrol system using a cleaner AI architecture based on Behavior Tree, Blackboard, a dedicated AI Controller, and a custom Behavior Tree Task.
This is the first episode of the Advanced AI Behavior System series. It continues from the earlier Enemy AI series, where the enemy logic was built mostly inside Blueprint. That older approach was useful for learning the basics, but it does not scale well once you start adding chasing, hearing, investigation, combat, cover behavior, and more advanced decision-making.
In this lesson, we move the enemy toward a better structure. The enemy character becomes the body, the AI Controller becomes the brain, and the Behavior Tree becomes the place where AI decisions are organized.
Watch the full video tutorial: Behavior Tree Basics for Simple Enemy Patrol in Unreal Engine
Subscribe for more Unreal Engine tutorials: Rambod Dev YouTube Channel
What You Will Build
By the end of this tutorial, you will have a basic enemy patrol system running through a Behavior Tree instead of old patrol logic placed directly inside the enemy character Blueprint.
The system includes:
- A duplicated enemy Blueprint used as the advanced AI version
- A cleaned enemy character Blueprint with old patrol and perception logic removed
- A new AI Controller dedicated to the advanced enemy system
- A Behavior Tree asset for controlling enemy behavior flow
- A Blackboard asset for future AI memory and decision data
- A custom Behavior Tree task that finds a random reachable patrol point
- An AI Move To setup that sends the enemy to that generated location
- A Sequence and Wait task to create a repeatable patrol loop
This is not the final AI system yet. It is the foundation. That is the point. If this structure is clean now, the next systems will be much easier to add.
Why Move from Blueprint Logic to Behavior Trees?
In small beginner projects, it is common to place most enemy logic directly inside the enemy Blueprint. That works for simple patrol, basic chase behavior, and quick tests. But once the AI grows, that Blueprint becomes a mess fast.
If you keep adding patrol logic, chase logic, hearing logic, attack logic, investigation logic, health logic, ragdoll logic, and decision logic inside one enemy Blueprint, the graph becomes painful to read and harder to debug.
A cleaner Unreal Engine AI setup separates responsibility:
- Enemy Character Blueprint: handles the body, mesh, movement component, health, ragdoll, and character-specific behavior.
- AI Controller: controls the enemy and starts the Behavior Tree.
- Behavior Tree: organizes decision flow, such as patrol, chase, attack, investigate, or return to idle.
- Blackboard: stores AI memory values like target actor, last known player location, patrol destination, or attack state.
- Behavior Tree Tasks: perform specific actions, such as moving to a patrol location or updating a Blackboard value.
That structure is much easier to expand than a giant enemy Blueprint full of disconnected logic.
Behavior Tree, Blackboard, and AI Controller Explained
Before building the patrol system, it helps to understand the main pieces.
AI Controller
The AI Controller is the brain that controls the enemy character. The enemy character is the body, but the AI Controller decides what that body should do.
In this tutorial, the AI Controller is responsible for running the Behavior Tree when the game starts.
Behavior Tree
The Behavior Tree is where the AI behavior is organized as a tree structure. It lets you build logic branches for patrol, chase, attack, hearing investigation, cover behavior, and other AI actions.
Instead of hardcoding everything in the character Blueprint, you build decision flow in a visual AI system designed for that purpose.
Blackboard
The Blackboard is the AI memory system. It stores values the Behavior Tree needs to make decisions.
In this first patrol episode, the Blackboard is mostly prepared for the future. Later, it can store values like:
- Target actor
- Last known player location
- Patrol location
- Whether the AI can see the player
- Whether the AI heard a sound
- Whether the AI is armed
- Whether the AI should attack or investigate
Behavior Tree Task
A Behavior Tree Task is a small action the tree can execute. In this tutorial, we create a custom task that finds a random reachable point near the enemy and moves the enemy to it.
That task becomes the core of the patrol behavior.
Step 1: Duplicate the Old Enemy Blueprint
Start by opening the Content Drawer and going to your AI folder.
If you followed the previous Enemy AI series, you should already have an enemy Blueprint, usually named something like:
BP_EnemyGuard
Right-click that Blueprint and duplicate it.
You can name the duplicated version:
BP_EnemyGuardAdvanced
or:
BP_EnemyGuardTwo
The exact name is not critical, but using a clear name is better. If this is your advanced enemy version, BP_EnemyGuardAdvanced is cleaner than vague names like Enemy2 or NewEnemyFinal.
The reason for duplicating the old enemy is simple: you do not want to destroy the old working system. The old Blueprint can stay as a backup while this new version becomes the Behavior Tree-based enemy.
Step 2: Clean the Enemy Blueprint
Open the duplicated enemy Blueprint.
Inside the Event Graph, you will probably see old logic from the previous AI system. This may include:
- Old patrol logic
- AI Move To logic
- AI Perception update events
- Forgotten target logic
- Movement speed changes
- Return to patrol logic
For the advanced version, most of that should be removed.
The reason is important. If you are moving toward Behavior Trees, the enemy Blueprint should not keep controlling the major AI decisions. Otherwise, you end up with two systems fighting each other: old character Blueprint logic and new Behavior Tree logic.
Keep only what belongs to the character itself, such as:
- Health component setup
- Health changed event binding
- Ragdoll or death logic
- Mesh and character-specific setup
Remove the old patrol and perception behavior from this new enemy version.
In the video workflow, the old Sequence node is also removed, and Event BeginPlay is connected directly to the health setup that still needs to run.
Brutally honest: if you keep all the old behavior logic while adding Behavior Tree logic, you are not upgrading the system. You are building a confusing mess.
Step 3: Create a New AI Controller
Now create the AI Controller that will run the Behavior Tree.
- Open the Content Drawer.
- Go to the AI folder.
- Right-click in empty space.
- Select Blueprint Class.
- Search for AI Controller.
- Create the Blueprint.
- Name it
BP_AIControllerAdvanced.
This AI Controller will become the brain for the advanced enemy character.
You may already have an AI Controller from the earlier series. Do not overwrite it unless you are sure you no longer need it. Keeping the old controller as a backup is safer.
Step 4: Create the Behavior Tree
Next, create the Behavior Tree asset.
- Right-click inside the AI folder.
- Go to Artificial Intelligence.
- Select Behavior Tree.
- Name it
BT_EnemyGuard.
This Behavior Tree will hold the logic for the enemy AI.
In this first episode, it will only handle random patrol. Later, the same Behavior Tree can grow into a more complete AI setup with player detection, chase logic, hearing response, investigation, attack behavior, and more.
Step 5: Create the Blackboard
Now create the Blackboard asset.
- Right-click inside the AI folder.
- Go to Artificial Intelligence.
- Select Blackboard.
- Name it
BB_EnemyGuard.
The Blackboard acts like the memory of the AI.
Even though this first patrol task does not require complex Blackboard data yet, creating the Blackboard now is still the right move because future episodes will need it. Chasing, target tracking, hearing, investigation, and combat logic all become cleaner when important state is stored in the Blackboard.
Step 6: Assign the AI Controller to the Enemy
Open your advanced enemy Blueprint, such as:
BP_EnemyGuardAdvanced
Select the root of the Blueprint or the character itself, then go to the Details panel and search for:
AI Controller Class
Set it to:
BP_AIControllerAdvanced
Compile and save.
This step is not optional. If you forget to assign the new AI Controller, the enemy will not use the controller that runs the Behavior Tree. Everything in the controller may look correct, but the enemy will still do nothing because it is not connected to the new brain.
Step 7: Run the Behavior Tree from the AI Controller
Open:
BP_AIControllerAdvanced
In the Event Graph, use:
Event BeginPlay
Drag from it and add:
Run Behavior Tree
For the Behavior Tree asset, select:
BT_EnemyGuard
Compile and save.
Now the chain is connected:
- The enemy character uses
BP_AIControllerAdvanced. - The AI Controller runs
BT_EnemyGuardat BeginPlay. - The Behavior Tree will decide what the enemy does.
At this point, the enemy has a body, a brain, and a Behavior Tree ready for logic.
Step 8: Build the Basic Behavior Tree Structure
Open:
BT_EnemyGuard
You will see the Root node. From Root, add a:
Selector
A Selector is useful when the AI needs to choose between different branches.
Later, this Selector can support logic such as:
- If the player is visible, chase or attack
- If a noise was heard, investigate
- If nothing important is happening, patrol
For now, there is only one branch, but using Selector from the start gives the tree a scalable structure.
From the Selector, add a:
Sequence
A Sequence runs its child tasks in order. For this patrol setup, the sequence will do this:
- Run the patrol task.
- Wait for a few seconds.
- Repeat.
Step 9: Create a Custom Behavior Tree Patrol Task
Inside the Behavior Tree editor, click:
New Task
Name it:
BTTask_Patrol
This creates a Blueprint-based Behavior Tree task.
Open the new task Blueprint.
This task will handle the actual patrol action. It will get the controlled pawn, find a random reachable location nearby, move the enemy there, and then tell the Behavior Tree when the task finishes.
Step 10: Use Event Receive Execute AI
Inside BTTask_Patrol, add:
Event Receive Execute AI
This event is the starting point for AI-specific Behavior Tree tasks.
It gives you access to:
- Owner Controller: the AI Controller running the task
- Controlled Pawn: the enemy character controlled by that AI Controller
For this task, the Controlled Pawn is the important reference because it is the actor that should move.
Step 11: Find a Random Reachable Patrol Location
From the Controlled Pawn, get:
Get Actor Location
This gives you the enemy's current world location.
From that location, add:
Get Random Reachable Point in Radius
Set the radius to:
5000
This tells Unreal's navigation system to find a random point within that radius that the enemy can actually reach.
This is better than choosing a random raw vector because a raw location may be inside a wall, outside the NavMesh, or somewhere the AI cannot path to. Get Random Reachable Point in Radius asks the navigation system for a valid patrol destination.
That is exactly what you want for a quick random patrol system.
Step 12: Move the Enemy with AI Move To
Add:
AI Move To
Connect the Controlled Pawn to the Pawn input.
For Destination, use the Random Location output from Get Random Reachable Point in Radius.
Set Acceptance Radius to something like:
10
or:
20
The Acceptance Radius controls how close the enemy needs to get before the movement counts as successful.
If the value is too low, the enemy may struggle to finish the task if it cannot reach the exact point. If it is too high, the movement may complete before the enemy gets close enough. For this simple patrol system, 10 or 20 is a reasonable starting range.
Step 13: Finish the Behavior Tree Task
From the On Success output of AI Move To, connect:
Finish Execute
Make sure:
Success = true
This tells the Behavior Tree that the patrol task completed successfully after the enemy reached the target location.
This part matters. If you do not call Finish Execute, the Behavior Tree may think the task is still running, and the tree flow may not continue correctly.
Compile and save the task.
Step 14: Add the Patrol Task to the Behavior Tree
Return to:
BT_EnemyGuard
From the Sequence node, add your custom task:
BTTask_Patrol
Then add a:
Wait
task after it.
Set the Wait duration to something like:
5 seconds
Now the flow is:
- Find a random reachable point.
- Move to that point.
- Wait for 5 seconds.
- Repeat the behavior.
This creates a simple patrol loop.
Behavior Tree Task Order Matters
Behavior Tree tasks run from left to right.
In the editor, you can see small numbers beside the tasks. Those numbers show execution order.
For this setup, the patrol task should run before the Wait task. That means the enemy moves first, reaches the patrol location, then waits.
If you place Wait before Patrol, the enemy will wait first and only move after that delay. That is not wrong, but it creates a different patrol feeling.
For this tutorial, the intended order is:
BTTask_Patrol
Wait
Not:
Wait
BTTask_Patrol
This is a small detail, but it changes the behavior immediately.
Step 15: Test the Enemy Patrol
Open your level.
Delete the old enemy actor from the previous AI system so it does not confuse the test.
Drag the new advanced enemy Blueprint into the level:
BP_EnemyGuardAdvanced
or whatever name you used for the duplicated version.
Press Play.
If everything is connected correctly, the enemy should:
- Start the new AI Controller.
- Run the Behavior Tree.
- Execute the patrol task.
- Find a random reachable point on the NavMesh.
- Move to that location.
- Wait for a few seconds.
- Repeat the loop.
That confirms your first Behavior Tree patrol system is working.
Common Problems and Fixes
The enemy does not move
Check whether the enemy has the correct AI Controller Class assigned. If it is still using the old controller or no controller, the new Behavior Tree will not run.
The Behavior Tree does not run
Open the AI Controller and make sure Run Behavior Tree is connected to Event BeginPlay, and that BT_EnemyGuard is selected as the Behavior Tree asset.
The patrol task runs but the enemy stays still
Make sure your level has a valid NavMesh. Press P in the viewport to visualize the green navigation area. If there is no NavMesh, the AI cannot find reachable points or move properly.
The enemy moves once but does not continue
Check whether Finish Execute is connected after AI Move To succeeds. If the task never finishes, the Behavior Tree may not continue to the Wait task or repeat cleanly.
The enemy waits before moving
Your Wait task is probably placed before the patrol task. Behavior Tree tasks run from left to right, so move BTTask_Patrol to the left of the Wait task if you want movement first.
The random patrol points feel too far away
Reduce the radius in Get Random Reachable Point in Radius. For example, use 2000 or 3000 instead of 5000.
The enemy stops too early or struggles to finish moving
Adjust the Acceptance Radius on AI Move To. A value like 10 or 20 is a good starting point, but some maps may need a slightly larger radius.
Why This Is a Better Foundation for Advanced AI
This patrol system is simple, but the structure is the real win.
You now have:
- A cleaner enemy character Blueprint
- A dedicated AI Controller
- A Behavior Tree controlling behavior flow
- A Blackboard ready for future AI state
- A custom Behavior Tree task for reusable patrol logic
From here, you can build more advanced systems without turning the enemy Blueprint into a disaster.
In future episodes, this setup can expand into:
- Player detection
- Chasing behavior
- Hearing perception
- Investigation logic
- Blackboard-driven decisions
- Environment Query System
- Armed enemy movement
- Taking cover
- Player down behavior
- Enemy shooting logic
That is why the setup matters. You are not just making the enemy walk randomly. You are preparing a system that can grow.
When to Use This Random Patrol Approach
This random reachable point patrol is useful when you want quick roaming behavior without placing manual patrol points.
Good use cases include:
- Simple guards wandering around an area
- Creatures roaming inside a zone
- Prototype AI movement
- Background enemies that do not need strict routes
- Early AI testing before building final patrol logic
However, this is not always the best solution.
If your game needs exact patrol routes, cinematic guard paths, stealth timing, or predictable level design, manual patrol points or Blackboard-controlled destinations may be better.
For this first Behavior Tree lesson, random reachable patrol is perfect because it keeps the logic simple while teaching the correct AI structure.
Conclusion
In this Unreal Engine 5 Behavior Tree tutorial, you created a cleaner enemy AI patrol system by duplicating the old enemy Blueprint, removing old patrol and perception logic, creating a new AI Controller, creating a Behavior Tree and Blackboard, assigning the controller to the enemy, running the Behavior Tree from the controller, and building a custom Behavior Tree patrol task.
The enemy now moves to random reachable locations, waits, and repeats the patrol loop through Behavior Tree logic instead of old character Blueprint logic.
This is the first step toward a much stronger Advanced AI Behavior System. The patrol behavior is simple, but the structure is correct. That is what matters at this stage.
Watch the full tutorial: Behavior Tree Basics for Simple Enemy Patrol in Unreal Engine
Subscribe for more Unreal Engine tutorials: Subscribe to Rambod Dev
Frequently Asked Questions
What is a Behavior Tree in Unreal Engine?
A Behavior Tree is an AI decision system that organizes enemy behavior into a tree structure. It lets you build cleaner logic for patrol, chase, attack, investigation, and other AI actions.
What is a Blackboard in Unreal Engine AI?
A Blackboard stores AI memory values used by the Behavior Tree, such as target actor, patrol location, last known player location, or whether the AI is currently chasing.
Why use an AI Controller instead of putting everything in the enemy Blueprint?
The AI Controller is the proper place to control AI decision flow. Keeping behavior in the controller and Behavior Tree makes the enemy Blueprint cleaner and easier to expand.
How do I make an enemy patrol with a Behavior Tree?
Create an AI Controller, run a Behavior Tree, add a patrol task, use Get Random Reachable Point in Radius to find a valid NavMesh point, then use AI Move To to move the enemy there.
Why is my Behavior Tree enemy not moving?
Common causes include missing NavMesh, wrong AI Controller Class, Behavior Tree not running from the controller, or the patrol task not calling Finish Execute.
Do I need a Blackboard for simple patrol?
Not always for the simplest version, but you should create one early because future AI logic such as chase, investigation, and targeting will need shared memory values.
What does Get Random Reachable Point in Radius do?
It asks Unreal's navigation system to find a random valid location near the enemy that can actually be reached through the NavMesh.
Why use a Sequence in the Behavior Tree?
A Sequence runs tasks in order. In this patrol setup, it runs the patrol task first, then the Wait task after the enemy reaches the destination.
Does task order matter in Behavior Trees?
Yes. Behavior Tree tasks execute from left to right. If Wait is placed before Patrol, the enemy waits first and moves afterward.
Is this patrol system good for stealth games?
It is a good foundation, but random patrol is not always ideal for stealth. For strict stealth design, manual patrol points or Blackboard-controlled routes usually give better control.
Continue Advanced AI Behavior System in Unreal Engine | Behavior Tree, Blackboard, EQS
Back to Advanced AI Behavior System in Unreal Engine | Behavior Tree, Blackboard, EQS playlist • Lesson 1 of 1