Getting AI to interrupt/abort Behavior Tree MoveTo Task

This is an old topic and there are many conflicting ideas for making this work spread across the forums. Here’s what I feel is the most elegant solution for UE5 using just a few very simple custom nodes.

Use case is the following: the AI agent should MoveTo a TargetActor. If during movement the TargetActor becomes unavailable, abort the MoveTo.
First of all, your MoveTo node needs “Observe Blackboard Value” enabled in the details panel. Here’s a simple node structure with just a single condition:

We use a SimpleParallel node with finish mode “Immediate”. The main branch of which executes the MoveTo.

The side branch has a custom Empty task which literally does nothing (=return succeeded). We Loop this task indefinitely until a given decorator condition evaluates to true. In my case, I am checking whether TargetActor cannot be equipped to the pawn’s equipment slot. If true, we want to abort.

Once this condition becomes true, the custom ClearBlackboardValue service node will be executed and it simply clears whatever value we have for TargetActor in the Blackboard. Thanks to “Observe Blackboard Value” the MoveTo will be aborted. You can also change the TargetActor to a different one, your AI agent will instead move towards the new TargetActor.

If the MoveTo finishes successfully then the looping of the Empty task will be aborted thanks to the SimpleParallel.

In case you still need the TargetActor after clearing, a simple copy of the blackboard key should be made beforehand.
You can add more AND conditions by adding more decorators to the Empty node.
You can add more OR conditions by adding more Empty tasks in a sequence and then looping the entire sequence.

3 Likes