Cannot stop Behavior tree, still runs after AI is killed

Whenever my AI dies I am not using ‘Destroy Actor’ because I want their body in the game still but the behavior tree keeps running no matter what I do. I plan on having a decent number of enemies and I do not want a whole bunch of behavior trees running in the background when there is no need. I just want the BT to go away to improve performance and stop other smaller bugs after an enemy dies.
I’ve tried 'Un Possess" node, it doesn’t do anything.

I keep hearing about this “Stop Logic” node but that doesn’t work either. If I have multiple enemies it gives errors everytime it is called.


And I even tried making a boolean variable to stop the flow in the BT once dead but that didn’t seem to work either. I may have set it up wrong but I’m not sure. I don’t even know if this would work properly, because the BT would still be running.


1 Like

Simple solution: use an “isDead” boolean.
When you set the AI to die, set the isDead bool to true.
Then, pass that value to the behavior tree at the top level and set “isDead is Not Set” shown in the image

That way, when the AI dies, it cannot continue its actions.

2 Likes

Also, a bonus is that you can have other AIs check that AIs bool to see if it should attack it or not.
If dead, the living AIs move on to the next one.

I’m trying to do what you said but it’s not working and I can’t figure out why. All I can tell you is that the “Hello” print string does fire when the creature dies, but the BT does not stop and I can’t tell if the IsDead boolean is changing or not.


Try using “get blackboard” node for the target for “Set Value as Bool”
Blackboard should be directly accessible in the Character BP.
No need to cast if it works.

Let me know if that works

Didn’t seem to make a difference. I used a different BB based condition whether or not the AI has seen the player and I’m trying to set this up the exact same way (but using a bool instead of an object, but it’s just not working.
I don’t even know how to test to find out where the problem is.

why do you put a reason? have you programmed that reason to work in c++?


It works for me but I have nothing in reason

I thought the reason was optional and I thought I may want to have it for later, even when I leave it blank it doesn’t make any difference at all.
In your picture what calls the LogicActivate function? How did you hook that up to a behavior tree?
Also I am not doing anything in c++

It is a function in my AI controller, which I call when I need it, like when the npc dies.

There is only one behavior tree per controller, it is not necessary to reference it.

Well, if reason empty doesn’t work for you, you may not be reaching the controller.

you may not have this field well filled in the character
image

2 Likes

You are a legend :smiley: i been looking through so many thing to try n get this but you had the answer i needed so thank you