A behavior tree is traversed from top to bottom and left to right. Every Task returns Running, Success, or Failure, and that status determines which Task is reached next. The examples below use Return Status Actions so the traversal order is visible without any gameplay logic; the numeric comment on each node is the order in which it is reached.

Choose a traversal rule

A Sequence traverses four child tasks from left to right until one fails.

Sequence runs its children left to right and continues only while each child returns Success. Here the Tasks commented "2" and "3" return Success and the Task commented "4" returns Failure. Sequence stops at that Failure and passes the status to its parent. There is no parent, so the tree ends.

A Selector traverses four child tasks from left to right until one succeeds.

Selector traverses in the same order but stops on the first child that returns Success rather than the first that returns Failure. Sequence and Selector are both Composite Tasks: Tasks that have several children and control the order and stopping rule for those children.

A Selector and nested Sequence show the numbered order in which their tasks are traversed.

The same rules apply to a larger tree. Tasks "1" through "4" are evaluated until "4" returns Failure, which stops the inner Sequence and passes Failure up to the Selector commented "1". A Selector does not stop on Failure, so traversal continues into the branch containing "6", "7", "8", and "9". Those all return Success, so the Sequence commented "6" completes and returns Success to the Selector.

Control a branch

A Conditional controls whether its Sequence continues to the following Action.

A Conditional Task inspects game state without modifying it and returns only Success or Failure. Here Can Execute? returns Failure, so its branch does not run and the top Selector moves to the right branch.

A Return Success decorator changes its child result before traversal continues.

A Decorator has a single child and modifies that child’s result or how often it runs. Return Success forces its branch to report Success regardless of the child’s own status, which satisfies the top Selector and prevents traversal from continuing to the right branch. The traversal rules are unchanged; only the reported status differs.

Parallel work and reevaluation

A Parallel starts several child tasks at the same time.

Parallel is a Composite that starts all of its children at once. Each branch still runs top to bottom and left to right internally; the difference is that sibling branches advance during the same tick instead of waiting for one another.

A failed Can Execute Conditional leaves the lower-priority Idle branch running.

Many behavior tree implementations reevaluate the entire tree every frame. Behavior Designer instead uses conditional aborts to reevaluate selected Conditionals only. In this tree Can Execute? is reevaluated while the lower-priority branch runs, so the branch can start as soon as its status changes:

Can Execute is reevaluated and interrupts the previously running Idle branch.

When Can Execute? changes status it issues an abort that stops Idle. Traversal appears to move right to left here, but only because the abort re-entered a higher-priority branch. See Conditional Aborts for the abort types and their scopes, and Performance for what reevaluation costs.

A Random Sequence chooses a non-sequential child execution order.

Composites control the order in which their children run, and some deliberately depart from strict left-to-right traversal. Random Sequence shuffles its child order when it starts, so the first child reached here is the second from the left. It applies the Sequence stopping rule to that shuffled order. Random Selector does the same for Selector.

Related:

  • Tasks lists every native Task by type.
  • Common Behaviors assembles these rules into complete gameplay patterns.
  • Sample Scenes orders the included scenes by the concept each one demonstrates.