Behavior tree stuck at trying to set variable?

So, I set a target variable for my AI to attack. However, once the target is destroyed, my AI gets stuck trying to set that variable. Is there a way to abort?

here’s the task:

and the relevant snippet of the tree:
image

Thanks in advance!

You need to hae some condition up the behavior tree if it is not met that aborts the sequence in case it is not met.

Hi! so I should add a decorator? the problem is, if i add a decorator Is enemy NOT set, then it simply goes into the sequence anyway.

While it’s impossible to completely analyze the situation from the snippet, one thing that sticks out is that you aren’t updating the nearest anamy actor value in case you’re not finding anything - it would make sense if the nearest enemy key was nulled.

I tried setting it to null in case it couldn’t find it, it still gets stuck on the GetOwnerTarget.

The task for getting the owner target, as shown above, just gets all actors of class Enemy, and returns the nearest one.

What do you want it to do in case no enemy is found? There are no blackboard-based conditions in the fight sequence or the selector above it, so unless the conditions somewhere else through the root of the behavior tree are changing, it will naturally keep on repeating.

For example, if no enemy targets are found, and in that case you would want the AI to exit combat, then you would update the blackboard value of IsInCombat to not set.

In case of no enemy being found, I want the ai to simply follow the owner by exiting combat. would I have to do that in the fight sequence as a BT decorator?

Sorry if it seems to obvious, I’m new at dealing with AI stuff.

The selector evaluates from left to right. If IsInCombat is set, it will choose the right path instead of the left.

So if you want to leave combat in case no enemies are found, just update the blackboard value of IsInCombat to not set and the selector will choose to go to the left path instead of right.

I owe you my life.