1
\$\begingroup\$

I'm using a custom Behaviour Tree library (not UDK or any other engine) so I'm wondering on the best way to cause an interrupt to a currently running node. I don't have decorators or parallel nodes in this library so looking for a different way to do it. I don't care about the specific reasons as to why the interrupt is needed. In general it just needs to tell the currently running node to stop running so the tree can be transversed again and that would find out the reason as the main "threats" would be checked.

I'm trying to think of a clean way to cause such interrupts in the tree. Generally the conditions that are already in the tree would be the reason for the interrupt (IsEnemyInRange, IsThirsty, IsHungry, etc) but if a node is running over multiple frames these don't get checked.

Any ideas given the above limitations I listed?

\$\endgroup\$
3

2 Answers 2

1
\$\begingroup\$

If you are using C#, you can use interfaces. Implement an interface in the base method of all your nodes, then create a broadcaster class to invoke the method on the required node.

If you are not using C#, you can use inheritance instead.

\$\endgroup\$
2
  • \$\begingroup\$ How would the broadcaster know when to interrupt? It seems like per action that would stay "running" I would want to define an existing condition(s) that should be ran when we go back into the active running node each time and if any of those return "success" to kill the active node and fail it so the next cycle will cause an iteration of the tree? \$\endgroup\$
    – user441521
    Commented Jul 31, 2016 at 20:08
  • \$\begingroup\$ @user441521 "When" to interrupt is a problem of the game designer, not the engine. \$\endgroup\$ Commented Aug 1, 2016 at 1:41
1
\$\begingroup\$

A solution that stays 'within' the language of Behaviour Trees, so to speak, would be to introduce a while node in your BT. Find a design that works for you, but one solution could be a composite node that always has exactly 2 children.

It will run (and reset and rerun) the first, and, as long is it is not failing, it will also run the second.

This will give the effect of guarding the execution of a sub-tree by some condition (e.g. "there have been no interrupts") that is checked on every tick.

Another BT abstraction that can work is a parallel node, another composite node, that takes any number of children, and run them all, failing when the first child fails, or succeeding when the first child succeeds etc. depending on your concrete use case. In this way, you can race LookForInterrupts with DoLongButInterruptibleAction, and if LookForInterrupts succeed, the entire node is killed.

\$\endgroup\$

You must log in to answer this question.

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