Assume I have a behaviour tree like the following:

   / | \
[B] [C] [D]
  • A = Selector (Priority node)
  • B = Perception task
  • C = Idle task
  • D = Walk to point task

The reason the tree looks like this is because B has priority over C and D since it should trigger alert procedures. In short, what I'm trying to model here is that the Agent sensors must have priority over behaviours.

Assume now the agent is in D and this node will continue returning running until the destination point is reached.

While D is running, something might happen (for instance, the NPC see or hear something) that should break the current operation as soon as possible but, D will go on regardless until it's done.

I know I could paste the sensors code on top of each tree leaf, like for example:

// kinda javaish pseudo code
void run() {
    // The node running method
    if (this.sensors.alert()) {
        return this.fail();

    // Else, keep going.
    if (! this.reachedGoal()) {
        // do the walking
        return this.running();

    return this.success();

But with that solution the "alert" behaviour is hard coded and out of the tree logic.

What solution do you suggest?

  • \$\begingroup\$ Are you using some library or framework for the implementation of the BT? Are you building your own BTs? \$\endgroup\$ – Leo Mar 6 '18 at 15:29
  • \$\begingroup\$ I was using an external library. I think i ended up coding a custom composite node type with the purpose of intercepting each tick and running the appropriate sensors \$\endgroup\$ – brazorf Mar 7 '18 at 9:30
  • \$\begingroup\$ I added a behavior-tree tag :) I agree, I found it strange too. \$\endgroup\$ – SashaZd Nov 11 '19 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.