Simple AI with Behavior Trees - Agro?

Hi everyone!

So im struggling a bit to make AI, and my struggle is within the Behavior Tree. Im managing to get the AI to follow the player or patrol around the navmesh - basically i’m able to get the AI to execute simple tasks. However, what I want to do is to make the enemies patrol and when the player is within a certain agro range, the AI should follow the player.

How would one manage the behavior tree in this cituation? I’ve tried all the tutorials I could find but I can’t get it to work. I should mention that i’m doing it in the third person example project.

TL;DR - How would I structure the behavior tree when I want AI to patrol around and then execute another task when the player is within a certain range.

Thanks for reading!
Best regards, Glacke

Hi Glacke,

To make this as simple as possible! What I suggest is a sequence node immediately after your Root node. This will allow you to control you execution, and prevent another node from being executed before the previous one finishes.

So in our case we create the first node Attack! which has a Decorator Found Enemy? . This node only executes if an enemy is found. Once an enemy is found, the node shouldn’t finish execution until the enemy is lost. I suggest putting this logic on the Pawn itself. So the enemy check is done by the Pawn, so the Decorator gets that information from the Pawn. Once the enemy is found, the Attack! node assigns a Event Dispatcher which is for your Enemy Lost Event on the Pawn itself. Once the enemy is lost, Pawn calls Enemy Lost. The node Attack! with the Enemy Lost Event Dispatcher Assigned is called finishing execution.

The next node is straight forward, this state gets the next route and moves towards it. Main node should be sequence to allow proper flow execution. Current route information should be stored in the Blackboard Asset.

So the idea is, should I be attacking now? No, keep patrolling. Usually this is the approach for FPS. Shoot or Don’t Shoot is the question.


Peter L. Newton

I agree, I’d just use a Selector where Peter used Sequence, and make the Patrol a Sequence. The main reason for it being that with the original setup you’d end up with the whole sequence failing if “Found Enemy?” failed, unless you added a kind of “always succeed” decorator on top of it. Needless complication. Use this:

I’d also suggest making the “Found Enemy?” condition simple Blackboard-based check if your Enemy key is set or not (and you course you’ll need to be writing your AI’s enemy information into blackboard).



Thank you both very much!

Just a quick question regarding the chart, what node should the found enemy/attack be? Same goes for patrol, is it a selector with a decorator or?

Glackie – were you able to figure everything out?

from my many months of searching no one can make a good aggro system any were its just not possible would love for someone to proof me wrong