1
\$\begingroup\$

I'll try to show my problem on a minimal example, in reality it's more complex: Behaviour Tree example

It's a simple behaviour, that repeats "an action" that has a certain animation. If a player gets close, this sequence gets interrupted and the AI executes the "Flee" action.

The interruption happens because the top level selector is "dynamic" which in Unity/NodeCanvas means, that its higher priority nodes get executed every frame and if they succeed they interrupt the lower priority ones.

My problem is shown via the red arrow - if the "action" gets interrupted, the clean up (in this case "stop animation") doesn't execute.

What is the best practice to handle the clean up? Is my setup flawed? Or should I just be using a different interrupting mechanism?

Thanks for any help!

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Make the cleanup part of the "Flee" node. When it wants to make the actor flee, then it first needs to make sure that all the pre-conditions which are required for fleeing are fulfilled. Like stopping any ongoing animations.

\$\endgroup\$
2
  • \$\begingroup\$ Won't that get super messy if there's 5 complex sequences in that top level selector and they all have to clean up each other's mess? I might have thought of a solution - since I can detect the interruption on single node (there is an OnStop callback): What if I write a custom "Interruptable Sequence" node that would execute the last child in both cases - when successfully completed or when interrupted. \$\endgroup\$
    – Paprik
    Feb 22, 2021 at 13:21
  • \$\begingroup\$ @Paprik Well, if each of these sequences requires a cleanup of all the others, then you perhaps only need one reusable "cleanup" node. And if there are special rules for each interruption regarding what needs to be cleaned up, then those would need unique logic anyway. Regarding inventing your own "Interruptible Sequence Node"... well most implementations of behavior trees end up with specialized composite nodes sooner or later. But when you jump to that option too early before you tried and exhausted all possible solutions with the standard nodes, then it can often end up even more messy. \$\endgroup\$
    – Philipp
    Feb 22, 2021 at 13:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .