Want to learn the fundamentals of behavior trees? Check out my tutorial, Get Started With Behavior Trees in Unity.
Behavior Trees are a fantastic way to write modular AI that can scale in complexity. Unfortunately, it can be quite hard to visualize how your tree is being executed which makes it difficult to debug potential failure points. The Behavior Tree Visualizer tool was created to solve these problems! The tool will scan for active behavior trees in your scene and group them in a drop down for easy toggle. A graph will be drawn, and nodes will light up, showing you which part of the tree is currently running.
Head over to the Wiki for more detailed documentation.
- Customize the graph by choosing the title bar color, the icon, amount to dim inactive nodes and more.
- Robust debug messages can be viewed directly on the graph. Surface anything you want to see.
- Includes basic node types to help you get up and running quickly. No need to write a sequencer, selector, inverter, or more!
This package comes with:
- Behavior Tree Visualizer tool built with Unity Toolkit (formerly UI Elements)
- Standard Behavior Tree nodes to get you up and running quickly
- Sample project to demonstrate the implementation
To import the package into your project, you can either download the .zip from the Releases tab or install through Package Manager with this URL: https://github.com/Yecats/UnityBehaviorTreeDebugger.git?path=/com.wug.behaviortreevisualizer
Here are the most important things to know:
- Your base Node must inherit from
NodeBase
. - Your node should call the
OnNodeStatusChanged
method when the node's status code or reason has been changed. This is what the tool listens to, to know which nodes should be highlighted, what their status is, and whether to draw any debug messages. - By inheriting
NodeBase
all nodes will have the notion of child node(s). Do not add anything to the list, and it'll be ignored (and thus, treated as a leaf node). Decorators (inverter, untilfail, etc.) should only ever have one child and composites (seqencer, selector, etc.) can have as many as they need. - Your MonoBehavior that runs the behavior tree must implement 'IBehaviorTree'. The tool scans the running scene for all references to this interface.
- Your base class must inherit from the
NodeBase
class. - Call
OnNodeStatusChanged
event when the node's status has been changed. In my example, I call it only if the all up status has changed (i.e.Running
toSuccess
) or if theStatusReason
has changed. Here's an example:
private string m_LastStatusReason;
if (LastNodeStatus != nodeStatus || !m_LastStatusReason.Equals(StatusReason))
{
LastNodeStatus = nodeStatus;
m_LastStatusReason = StatusReason;
OnNodeStatusChanged(this);
}
- This project uses icons from https://game-icons.net/