Artificial Intelligence: Behavior Trees Part 4

Types of Decorator Nodes

Decorator nodes only have exactly one child node, and their purpose is to somehow alter the functionality of that individual child node through some sort of operation. You can think of Decorators as “manipulators”, since they are ultimately used to manipulate the return statuses of its only child. Common examples of Decorator nodes are inverting the returned status of its only child node, repeating the processing of the child node, or terminating its child node.

  • Inverter - Inverter Decorator nodes are used to negate the result of their child node’s returned status In other words, if the Inverter’s only child node returns “Success”, then the Inverter sends “Failure” back up to its parent. If the Inverter’s only child node returns “Failure”, then the Inverter sends “Success” back up to its parent. Inverters are often used in conditional tests.

  • Succeeder - Succeeder Decorator nodes ALWAYS return “Success” back to its parent, regardless of the returned status of the Succeeder’s child. This is extremely useful in cases where you anticipate “Failure” in some branch of the tree and when you don’t want to abandon processing of a sequence that that branch contains. Fun Fact: There is no need to create an opposite “Failer” Decorator node because you can easily attach an Inverter as the parent to the Succeeder to always guarantee “Failure” is returned back up the tree!

  • Repeater -A Repeater Decorator node reprocess its child node each time the child node returns a status back up. You can also use Repeaters to reprocess the child node a fixed number of times too, like a loop. Repeater Decorator nodes are commonly used towards the top of Behavior Tree to allow for the tree to run continuously.

  • Repeat Until Fail - A “Repeat Until Fail” Decorator node acts in the same way as the Repeater. It reprocesses its child node each time UNTIL the child node returns a “Failure” status. Once the “Repeat Until Fail” node receives the “Failure” status message from its child, it returns “Success” back up the tree.