Build Behavior Trees
through composition
ClosureBT is a modern behavior tree framework for Unity that uses C# closures and async patterns to create intuitive, maintainable AI systems.
Quick Start
Create your first behavior tree in just a few lines of code:
AI = Sequence("NPC", () =>
{
Wait(1);
Do(() => Debug.Log("Hello"));
Selector("Make A Choice", () =>
{
Sequence(() =>
{
Condition("Is Angry", () => IsAngry);
Pickup("Egg");
ThrowItemAt(() => Target);
});
SomeOtherAction();
});
Dance();
MoveTo("Bed");
}); AI = Sequence("NPC", () =>
{
Wait(1);
Do(() => Debug.Log("Hello"));
Selector("Make A Choice", () =>
{
Sequence(() =>
{
Condition("Is Angry", () => IsAngry);
Pickup("Egg");
ThrowItemAt(() => Target);
});
SomeOtherAction();
});
Dance();
MoveTo("Bed");
}); Key Features
- → Embedded DSL — Clean and simple DSL for declaring nodes
- → Composition based API — Compose behaviors through functions
- → Time Travel Debugging — Visual debugger with the ability to scrub through execution history
- → Async Support — Lifecycle methods with synchronous and asynchronous paths
- → Graceful Interruptions — Handle interruptions predictably and reliably with lifecycle methods
- → Parameterized Nodes — Create nodes that can accept parameters and return values
- → Recursion — Nodes can be recursive, enabling things such as Task Decomposition
Core Concepts
Nodes
The fundamental unit of execution. Each node has a status (Running, Success, Failure) and executes through lifecycle hooks.
Variables
Type-safe local state storage. Variables support reactive signaling to notify on value changes.
Lifecycle Hooks
Hooks like OnEnter, OnTick, OnExit let you define behavior at each execution phase.
Node Reference
Explore our comprehensive node reference guides for all available node types.
Composite Nodes
Overview of all Composite Nodes — Container nodes that hold and organize child nodes to define execution patterns like sequencing, selection, and parallelization.
Leaf Nodes
Overview of all Leaf Nodes — The fundamental execution units that perform actual actions, check conditions, and manage timing within composite nodes.
Decorator Nodes
Overview of all Decorator Nodes — Utility nodes that wrap and modify the behavior of other nodes with patterns like repetition, conditions, and timing.
Next Steps
Check out our Crash Course to get started quickly with practical examples and step-by-step guidance.
Or dive deeper into the Core Concepts documentation to understand the foundation in detail.