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 is where you layout the general structure of your behavior tree. Here you can select, create, delete, and move your Nodes.
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.
There is also an extra option if you right click on the Behavior Tree node itself.
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 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).
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.
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).
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.
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.
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.