What is a Behavior Tree?

Behavior trees are a popular AI technique used in many games. Halo 2 was the first AAA game to use behavior trees and they started to become more popular after a detailed description of how they were used in Halo 2 was released. Behavior trees are a combination of many different AI techniques: hierarchical state machines, scheduling, planning, and action execution. One of their main advantages is that they are easy to understand and can be created using a visual editor. Some would even say that they are the cornerstone of modern AI:

At the simplest level behavior trees are a collection of tasks. There are four different types of tasks (action, conditional, composite, and decorator) and the arrangement of these tasks determine how your AI functions.

This is a simple behavior tree that packs a lot of functionality. The flow page goes into more details, but behavior trees execute from top to bottom, left to right. In this case when the tree first starts it has a Can See Object task which detects if the agent can see the player. If the agent cannot see the player then Can See Object will return a status of failure and the tree will move onto the next task. The Sequence and Selector tasks determine which task should be transitioned to next. In this case the rightmost Patrol task will run next since Can See Object returned failure.

Eventually the agent will see the player and Can See Object will return success. When it returns success the Sequence task will run the next task which contains both Seek and Attack. This will cause the agent to Seek to the player and then attack.

One of the huge advantages of behavior trees is its visual editor. In this case if we instead wanted the agent to start seeking as soon as the player is within distance instead of sight as well have to do is switch out Can See Object for Within Distance.

With this we were able to instantly change the functionality of the AI by swapping out a task. Behavior trees also have an advantage during debugging – during runtime you can see the active task as well as inspect the values.

The green indicates that the task is currently active. On the top right of the task the execution status of the task is also displayed. We can change the values at runtime, such as the Target field in this example. The visual editor and debugger are the most prevalent advantages of behavior trees, and there are many other features that make behavior trees the cornerstone of AI.

Behavior Designer Pro takes all of these concepts and packages it up in an easy to use interface with a flexible API. Behavior Designer Pro also uses DOTS as its backend ensuring your AI is as efficient as possible. You do not need to be familiar with DOTS in order to get the advantages of Behavior Designer Pro. Behavior Designer Pro contains more than 15 sample scenes in order to get you started. New tasks can be created by extending from one of the task types. In addition, many videos have been created to make learning behavior trees as easy as possible.

When you are just getting started it is recommended that you start with this tutorial. From here you’ll be able to apply the same building blocks to create a much more advanced AI logic.