Behavior Trees are composed of nodes, which are divided in three categories: composite, decorators and leafs.
Leaf Nodes do not have any child. They perform some computation and return a state value. There are two types of Leaf Nodes:
- Conditions: A condition node checks whether a certain condition has been met or not. The node must have a target variable and a criteria to base the decision. They can only return SUCCESS or FAILURE.
- Actions: An action node performs computations to change the agent state. They return SUCCESS, FAILURE or RUNNING (while executing the action)
A Composite Node (in RAIN BT known as Decision nodes) can have one or more children. The node is responsible to propagate the tick signal to its children, respecting some order. There are several types of Composite nodes:
- Selector (aka Priority): A selector node ticks its children sequentially until one of them returns SUCCESS, RUNNING or ERROR. If all children return the failure state, the priority also returns FAILURE. Use selector nodes when you need it to execute nodes until it returns a success on one (for example, if first task returns FAILURE, it moves to second task, and so on).
- Sequence: A sequence node ticks its children sequentially until one of them returns FAILURE, RUNNING or ERROR. If all children return the success state, the sequence also returns SUCCESS. Use sequence nodes when you need tasks to execute successfully one after the other until one fails (for example, to get to the third task, the previous two tasks have to return SUCCESS).
- Parallel: The parallel node ticks all children at the same time, allowing them to work in parallel. This node is a way to use concurrency in Behavior Trees. Notice that, using this node, the parallelization is contained locally, avoiding losing control of the execution flow as happens on the FSM. Parallel nodes return SUCCESS if the number of succeeding children is larger than a local constant S (this constant may be different for each parallel node); return FAILURE if the number of failing children is larger than a local constant F; or return RUNNING otherwise.
Decorators are special nodes that can have only a single child. The goal of the decorator is to change the behavior of the child by manipulating the returning value or changing its ticking frequency.