User Tools

Site Tools


behaviortrees:behaviortreeeditor

Behavior Tree Editor

The Behavior Tree Editor is where you go to create behavior for your AI. Behavior Trees are used by the Basic Mind to move, animate, sense, and make logical choices.

The Behavior Tree Editor consists of two panes: the Tree Editor and the Inspector.

The Tree Editor

The Tree Editor is where you layout the general structure of your behavior tree. Here you can select, create, delete, and move your Nodes.

Right Click Menu

When you right click on any node you will get a context menu with a number of choices. Depending on the node you click on, these options may change as well.

  • Switch To: This option will only show up for Decisions. It allows you to switch a Decision to a different type without having to create a new one and copy all the children out.
  • Delete: This will delete the currently selected node.
  • Cut: This will cut the currently selected node. It copies the node and then deletes it from the current tree. The copied node can be pasted in a different location, or in a different tree.
  • Copy: This will copy the currently selected node. The copied node can be pasted in a different location, or in a different tree.
  • Paste: This pastes the currently cut or copied node at the current location.

There is also an extra option if you right click on the Behavior Tree node itself.

  • Clear Debug Breaks: This turns all Debug Break options to false in this behavior tree.

Clicking and Dragging

You can select any node by left clicking it in the Tree Editor. This will also change what properties are displayed in the Inspector.

For any Decision node, if you left click its icon, or double click its row, it will hide or show its children.

If you click and drag a node in the Tree Editor it will allow you to move the node. You can cancel the move by pressing the Esc key. If you hold down the Ctrl key while dragging (or after you start dragging) you can copy the node instead of moving it.

The Inspector

The Inspector is where you can select which behavior tree you are working on as well as change node specific properties.

You can change the size of the Inspector by going to the RAIN Settings asset (you can also use the The RAIN Menu to get to it).

Creating and Loading

The first option in the Behavior Tree drop down is to display the behavior tree of the Current AI. If no AI is selected (or if it doesn't have a behavior tree) it will indicate that.

The second option is Create New Behavior Tree, which will display a popup when selected, allowing you to choose the name for your behavior tree. This will automatically be created in the current behavior tree save directory (also changeable in the RAIN Settings asset) and opened up.

There are also three buttons that will be present whenever a behavior tree is selected.

  • Reload: Primarily here in case something goes wrong. This will reload the behavior tree from the asset currently saved.
  • Import XML: Allows you to import a previously exported behavior tree. It will replace the currently selected tree with the XML it reads in.
  • Export XML: Allows you to export the currently selected tree into an XML format. This can be useful if you need to share a tree outside of RAIN.

Debugging

Sometimes it can be difficult to understand what is going wrong with a behavior tree, so the Behavior Tree Editor also enables you to debug your trees while your scene is playing.

Debugging only works for the currently selected AI and the Behavior Tree Editor must have the Current AI behavior tree selected (first option in the drop down).

Colors and Display

Each node that is currently running in the Tree Editor will be highlighted according to its return value. The Inspector will also show an additional box indicating the return value.

  • Green: indicates Success.
  • Red: indicates Failure.
  • Yellow: indicates Running.
  • Orange: indicates Repeating.

Since behavior trees are executed every Update it can sometimes be difficult to see the changes in the tree. To help with this you can pause and step the Unity Editor and you can also set breakpoints in your tree.

Breakpoints

Every node within your behavior tree has an additional option on it called Debug Break. When checked, the behavior tree node will execute a Debug Break when it is first started.

Given the way Debug Break works, in many cases the tree will continue executing past the node that triggers the break. This is because the Unity Editor finishes the current Update before pausing. If you need to stop before a particular node executes it can be useful to use a Yield node with its Debug Break checked. Since a Yield node always returns Running once, this will guarantee your execution will stop at that exact point.

It is important to realize that Debug Break affects a behavior tree even if it isn't being debugged at that moment. This means the Unity Editor may be paused even if the Behavior Tree Editor is closed, or if a different AI is currently selected, or if you have multiple AI using the same behavior tree.

At any point you can right click the Behavior Tree node and Clear Debug Breaks to remove all breakpoints within the current behavior tree.

behaviortrees/behaviortreeeditor.txt · Last modified: 2022/09/29 15:51 by sigil