# How to cancel a task correctly? (Behavior tree -\> MoveTo)

**URL:** <https://forums.unrealengine.com/t/how-to-cancel-a-task-correctly-behavior-tree-moveto/1781224>\
**Category:** AI\
**Tags:** unreal-engine, question\
**Created:** [April 1, 2024, 3:33am UTC](https://forums.unrealengine.com/t/how-to-cancel-a-task-correctly-behavior-tree-moveto/1781224 "2024-04-01T03:33:11Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [April 1, 2024, 3:33am UTC](https://forums.unrealengine.com/t/how-to-cancel-a-task-correctly-behavior-tree-moveto/1781224/1 "2024-04-01T03:33:11Z")

</div>

I’m testing this simple behavior tree.

 ![Captura de pantalla 2024-04-01 033634](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/9/4/e94b610ec8139c8d8aaa82d2e321087cd7689298.png)

The thing is, stopping the task (Move to) is a pain.

In the first case: (Decorators without abort self option)  
Decorators don’t work until the task fails or reaches the goal…  
So in this case they are not useful to stop the task.

In the second case: (Decorators with abort self option)  
Decorator aborts task continually. The bot has not a continuous movement.  
I don’t want this either… it doesn’t seem natural.

Neither of the two behaviors above are useful.  
I simply want to abort the task immediately when the variable is not set.  
What is the trick to do it well?  
Thank you so much!!

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [April 1, 2024, 6:51am UTC](https://forums.unrealengine.com/t/how-to-cancel-a-task-correctly-behavior-tree-moveto/1781224/2 "2024-04-01T06:51:10Z")

</div>

Ok… this way seems to work well  
-Aborts lower priority and reorganize branches like this.

 ![Captura de pantalla 2024-04-01 074309](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/d/6/0d6651dda585bb7428238cadc8ee9abd1bd19498.png)

The previous solution is not feasible for large trees.  
If anyone knows a better way please let me know.

Thank you!!

* * *

i see a lot of people are totally lost tryding to stop “MoveTo” since teen years ago… 😱

> [@Getting AI to interrupt/abort Behavior Tree MoveTo Task](https://forums.unrealengine.com/t/getting-ai-to-interrupt-abort-behavior-tree-moveto-task/306919/16):
>
> Somehow, even changing the abort condition to lower, won’t interrupt the pawn from running the lower branch’s moveTo completely before restarting the BT even when I follow closely to it as a pawn. Once it reaches its waypoint, the tree resets then goes for the left branch.

* * *

---

<div class="post-metadata">

**Author:** ![Auran131](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Auran131](https://forums.unrealengine.com/u/Auran131)\
**Post date:** [April 1, 2024, 11:48am UTC](https://forums.unrealengine.com/t/how-to-cancel-a-task-correctly-behavior-tree-moveto/1781224/3 "2024-04-01T11:48:58Z")

</div>

there is an execute abort or similiar node, on that you can call stopallmovementimmediately()

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [April 1, 2024, 5:17pm UTC](https://forums.unrealengine.com/t/how-to-cancel-a-task-correctly-behavior-tree-moveto/1781224/4 "2024-04-01T17:17:19Z")

</div>

Thank you so much for that alternative solution. ❤

Seem there is several ways to do it… But also seem each one work in a different scenario.

That explains why over 10 years people came up with so many different solutions.

---

<div class="post-metadata">

**Author:** ![zhanginin](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@zhanginin](https://forums.unrealengine.com/u/zhanginin)\
**Post date:** [April 9, 2024, 3:19am UTC](https://forums.unrealengine.com/t/how-to-cancel-a-task-correctly-behavior-tree-moveto/1781224/5 "2024-04-09T03:19:34Z")

</div>

I use a btservice to update stop move or not,use a blackboard decorator to stop moveto node,and use forcesuccess decorator to force stopmove node success,so the following nodes can be executed.And don’t forget to call stopmove so the AIMoveto Task (back in the moveto node)will stop.  
 ![BTExampleStopMove](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/1/6/41645c801b7eeeffeab38a1effda91a1ddab93bb.png)
