Skip to content

Logic

A Behavior Tree always starts its execution from the root Entry node and trickles down following a top-to-bottom fashion, looking for a single Task or Sub Graph node type.

Once one of these nodes has been found it executes them and the result of the execution bubbles up following the same path. During this phase, Decorators might change the returning value.

The return value of a node (and therefore, the return value of a behavior tree) can be:

  • Success: The node has ran and successfully completed
  • Failure: The node has attempted to run but unsuccessfully completed
  • Running: The node is running and has not finished

Apart from these states, a node can also be in a ready state, which means it has yet to be executed.

Failure is useful

A common misconception is that a Failure state is due to an error, which is not true. A Failure state could be due to a character not being able to see the Player and moving on to checking another branch on a Selector node.

Every time a Behavior Tree is evaluated, whe whole tree structure is checked, taking into account the state of all nodes, which are carried over. For example, a node that has been Success ran won't run again unless the tree finishes with a Success or a Failure state.

Once a Behavior Tree has finished running and has a Success or Failure state it is considered as finished.

Ordering Nodes

Composite nodes can have multiple children branching from them. The order in which these are executed is denoted by a numeric value at the top of their children, and it's automatically calculated when moving a node around.

Ordering nodes in a Behavior Tree

The left-most branching node will be the first one, and the last one will be the one found at the right-most position.