Documentation

Learn how to use NodeCanvas

Download PDF Version

Behaviour Trees

Overview

Behavior Trees are commonly used in modern games and applications, to create dynamic behaviours by using small building blocks (nodes) that perform a certain task and control the flow of the behaviour for one or even more AI agent. Behaviour Trees can be thought as a simplified programming language, that though contains the most common down to the core of the operations needed such as conditions, actions, loops, sequencer and selections to name a few. NodeCanvas allows you to make such Behaviour Trees visualy, without the hassle or the need to understand the whole low level underline logic, but rather only the top high level one.

On each update (called a Tick) of the Behaviour Tree, it starts by executing the first node. That node will then perform a small task and return it’s status, either Succeeded,  Failed, or not yet decided, meaning Running among some others (see later). Depending on the type of node that decision may stem either from itself or be determined based on one or more of it’s child nodes. As such there exist three disnstictive types of nodes a Behaviour Tree can have, those being:

Leaf Nodes

Leaf nodes have no child nodes and they are the final destination of a Behaviour Tree tick, hense their name. Most commonly leaf nodes will either check a Condition; a state of the game, or perform an Action, altering the state of the game.

Composite Nodes

Composite nodes mostly exist to determine the flow of the Behaviour, controling which leaf nodes are going to be executed or in what order for example. As such, Composite nodes may have any number of child nodes, which will “ask” on how to proceed. The most basic of Composite nodes are the Sequencer, which executes all it’s child nodes in order until one Fails, and the Selector which executes all it’s child nodes until one Succeeds. The most reasonable way to think of those two, would be an AND and an OR in case you are familiar with boolean logic. If you are not, that’s still fine and you don’t have to be to use Behaviour Trees.

Decorator Nodes

Decorator nodes are special in what each do, but generaly speaking they exists to somehow alter the functionality of their one and only child node that they can have. Common Decorators include Looping the child node for a number of times, Limiting access to a child node or Interrupting a child node’s execution to name a few. NodeCanvas comes with a handfull of Decorator nodes to allow faster and more flexible behaviour creation  than usual.

Status Reference

As stated earlier, each node returns a Status. Here is a reference of the possible Status nodes can return/be at and what they are used for:

  • Resting, is a status which marks a node as “ready”, and it’s the status that nodes are set to, after each traversal when the tree resets. You should generally never return Status.Resting.
  • Success, means the node succeed in it’s task.
  • Failure, means the node failed in it’s task,
  • Running, means the node is still running and final status to be determined.
  • Error, is a status that usually is returned when there is an execution error (like for example a required reference is not set). Status.Error, is unhandled by the parent node (neither Success, nor Failure), which means that the parent node will simply continue it’s execution as if the node that returned Status.Error was not even there.
  • Optional, which similar to the above, in that it is also unhandled and means that the parent node will continue it’s execution as if the node that returned Status.Optional was never there. The difference with Status.Error of course, is that Status.Optional is deliberatly optional.

Further Reading

If you want to further understand the logic behind Behaviour Trees, here are a few very interesting links:
AltDevBlogADay
ChrisSimpson (Gamasutra)
AIGameDev
GaveDev.StackExchange
ITU.dk
cse.scu.edu (far more than Behaviour Trees)

Yes No Suggest edit
7 of 7 users found this section helpful
Suggest Edit