# How to Set Up Basic Enemy AI Using Behavior Trees to Follow the Player in Unreal Engine? 

**URL:** <https://forums.unrealengine.com/t/how-to-set-up-basic-enemy-ai-using-behavior-trees-to-follow-the-player-in-unreal-engine/2652365>\
**Category:** Blueprint\
**Tags:** unreal-engine, question\
**Created:** [August 30, 2025, 2:38pm UTC](https://forums.unrealengine.com/t/how-to-set-up-basic-enemy-ai-using-behavior-trees-to-follow-the-player-in-unreal-engine/2652365 "2025-08-30T14:38:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![auroraxhiuhiu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@auroraxhiuhiu](https://forums.unrealengine.com/u/auroraxhiuhiu)\
**Post date:** [August 30, 2025, 2:38pm UTC](https://forums.unrealengine.com/t/how-to-set-up-basic-enemy-ai-using-behavior-trees-to-follow-the-player-in-unreal-engine/2652365/1 "2025-08-30T14:38:11Z")

</div>

Hi everyone,  
I’m fairly new to Unreal Engine, and I’m currently working on setting up a basic enemy AI using **Behavior Trees**. I want the enemy to detect the player and follow them around the level.

So far, I’ve done the following:

- Created a basic **NavMesh** and placed it in the level.

- Set up a basic **AIController** for the enemy character.

- Created a simple **Behavior Tree** to move the enemy to a target location.

But I’m having trouble getting the enemy to continuously follow the player. I’ve read that you can use **AI Perception** to detect the player, but I’m unsure how to integrate this with the **Behavior Tree** so that the enemy keeps following the player once they’ve been detected.

Here are a few specific questions I have:

1. How do I properly use **AI Perception** to detect the player?

2. Once detected, how do I set up the **Behavior Tree** to make the enemy follow the player in real-time?

3. Do I need to use a specific **blackboard key** to store the player’s location for the AI to follow them?

Any advice or beginner-friendly tutorials would be greatly appreciated. Thanks in advance!

---

<div class="post-metadata">

**Author:** ![RedGrimnir](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/redgrimnir/32/1054683_2.png) [@RedGrimnir](https://forums.unrealengine.com/u/RedGrimnir)\
**Post date:** [August 30, 2025, 3:05pm UTC](https://forums.unrealengine.com/t/how-to-set-up-basic-enemy-ai-using-behavior-trees-to-follow-the-player-in-unreal-engine/2652365/2 "2025-08-30T15:05:15Z")

</div>

Hi Welcome!

There are many aspects to it however I suggest starting with a tutorial like [this one](https://www.youtube.com/watch?v=-t3PbGRazKg&t=2379s), something nice not a hacky one.

In terms of your question in high level

1. Think about states. Let’s say your AI logic have states of normal, alerted, agroed, dead. In each state AI should behave differently. Like in Agroed state it attacks all time, maybe hides a bit, if too much distance walks to you, if distance is right tries shoot, or maybe so close uses a shield ability etc. In short once AI is in agroed state (Once it detected an enemy) you don’t have to continuously detect it, it already knows that there is an enemy and acts on it. In further stages you can define what makes AI go out of this state? Does it follows to the enterance of the dungeon? Turns back and goes to its original place etc. etc. The point is start with the States (contexts) of what AI is in.
2. Once a state is changed you can have a selector in behaviour tree and just that part of the behaviour tree runs. Like EnumState=Agroed-\>CheckDistance-\>MoveToTarget-\>TryShoot-\>EQS Strafe-\>MoveToLocation(Strafe)-\>CheckDistance-\>TryShoot -\>CheckTargetIsValid? (not dead) etc. and you can loop in this state forever if you like. A better more advanced way would be using State BlackBoards this way logic is super extendable organised for bigger games and ai archetypes and its reusable however that would require quite a C++ knowledge. Start with small steps as Selectors in Behaviour Tree and Enums as state.
3. Well once you have an attack target it is good to pass that to BB since you will do alot of things with it. Once you give the object(actor) reference of the attack target then you can query location, health of target etc on the behaviour (AI) Side

Start with that tutorial you will be fine and think around as designer advice  
**What states my ai has in my game in terms of the gameplay?**

-Deploying  
-Hybernating  
-Sleeping  
-Immobilized  
-KockedBack  
-Normal  
-Alerted  
-Agroed  
-DBNO (Dead but not out, on the ground maybe looking for a healer? dying and making a suicide attack? )  
-Dead  
etc etc and the rest as you as in Agroed State defining the behaviour in simple terms.

Let me know if it helps.
