Table of Contents

Behavior Trees

Behavior Trees are primary features of RAIN{one}. The BehaviorTreeMind allows for task-oriented, hierarchical decision making and is capable of very complex, goal-driven AI logic. RAIN{one} makes behavior tree creation and modification easy through the use of a Behavior Tree Editor tool. Behavior trees can even be reused by multiple AI.

Behavior trees are stored as .xml files in the AI→Resources→BehaviorTrees folder in Assets.

To read more about creating behavior trees, see Create New Behavior Tree.

Theory

A Behavior Tree is a way of organizing decision logic for your AI. It has grown in popularity throughout the industry after its successful use in Halo 2. Behavior Trees are based on the concept that decision making for an AI can usually be broken down into a set of hierarchically organized tasks. Higher level tasks near the root of the hierarchy usually define a mechanism for choosing between or organizing the execution of lower level tasks. Tasks at the bottom or edge of the tree (usually “leaf nodes” in programming parlance) are typically specific actions that can be carried out by game logic. In RAIN{one}, these tasks take the form of behavior tree nodes.

Behavior Trees differ from another common approach, state machines, in that they are organized in a context specific fashion. State machines tend to define the most important states of the environment and the AI, and then define actions that can be taken to move to other states, as well as decision logic for choosing between these state transitions. Behavior Trees, on the other hand, only deal with state information as it pertains to execution of a set of tasks that are already under way. The logic of behavior trees facilitates a “fallback” model in which tasks that can’t be accomplished automatically fall back to alternate methods. This allows developers to concentrate on designing intended behavior rather than attempting to design for all possible alternatives.

In RAIN{one}, there are 3 common node types: logic, conditionals, and actions. Logical nodes, such as Sequencers or Selectors (described later), are used to define how the AI chooses between a set of possible options and to describe how to execute a sequence of tasks that work together. Condition nodes use information stored in the AI ActionContext to determine branching tests (e.g., if “X” is true, choose option A, otherwise try something else). Action nodes are used to deliver instructions to the AI to execute game logic or trigger an event in the game world. This can be anything from playing a sound effect to starting an animation, moving, or just executing a custom code segment. Visit the nodes page to read more about the various nodes that RAIN{one} supports.

There are many excellent articles that cover behavior tree theory in more detail at AIGameDev.com.

Execution

Behavior trees start execution with the first node in the tree, known as the root node. In RAIN{one}, however, behavior tree files can contain multiple top-level nodes. This allows for multiple trees to exist in the same behavior tree file. Because of this, each AI must specify its root node in its BehaviorTreeMind.

Execution occurs during LateUpdate, starting with the root node. Logic nodes can contain other nodes and determine how execution passes to those child nodes. For instance, sequencer nodes will transfer execution to each child node, in order, as long as none of the nodes fails. In addition to failure, there are two other results that a behavior tree node can return: success and running. For both success and failure, execution will exit the node and continue as normal. For a result of running, execution will pause on that node and return to it on the next execution step.

behavior/behaviortrees/start.txt · Last modified: 2022/09/03 13:47 by Eridanus