Tutorials
Learn by building. These tutorials walk you through creating real-world behavior trees for games, robotics, and automation. Each tutorial includes a complete tree you can import into the editor.
๐ฎ Game AI Tutorials
Tutorial 1: Patrol Bot with Alert System
Goal: Create an NPC that patrols between waypoints, investigates disturbances, and returns to patrol after investigation.
Difficulty: Beginner | Time: 15 minutes
Tree Structure
Selector "PatrolOrInvestigate"
โโ Sequence "InvestigateDisturbance"
โ โโ Condition "IsDisturbanceDetected"
โ โโ Action "MoveToDisturbanceLocation"
โ โโ Action "LookAround"
โ โโ Action "ReturnToPatrolRoute"
โ
โโ Sequence "ContinuePatrol"
โโ Decorator "RepeatForever"
โ โโ Sequence "PatrolLoop"
โ โโ Action "MoveToWaypoint_A"
โ โโ Action "Wait" (duration: 3s)
โ โโ Action "MoveToWaypoint_B"
โ โโ Action "Wait" (duration: 3s)
โ โโ Action "MoveToWaypoint_C"
Step-by-Step Instructions
- Open Behavior Tree Editor and clear the canvas
- Drag a Selector node onto the canvas (this is your root)
-
Add two children to the Selector:
- A Sequence named "InvestigateDisturbance"
- A Sequence named "ContinuePatrol"
-
Under "InvestigateDisturbance", add:
- Condition: IsDisturbanceDetected
- Action: MoveToDisturbanceLocation
- Action: LookAround
- Action: ReturnToPatrolRoute
- Under "ContinuePatrol", add a Decorator โ RepeatForever, then add a Sequence with patrol actions inside
- Export as JSON and test in your game engine
The Selector ensures that investigation takes priority over patrol. When a disturbance is detected, the first branch succeeds and the patrol branch is never evaluated. Once investigation completes, the tree restarts and patrol resumes.
Tutorial 2: Enemy AI with Health-Based Behavior
Goal: Design an enemy that changes tactics based on health level: aggressive when healthy, defensive when injured, and fleeing when critical.
Difficulty: Intermediate | Time: 25 minutes
Tree Structure
Selector "EnemyBehavior"
โโ Sequence "FleeWhenCritical"
โ โโ Condition "IsHealthBelow" (threshold: 20%)
โ โโ Action "FindCover"
โ โโ Action "MoveToFleePoint"
โ
โโ Sequence "DefendWhenInjured"
โ โโ Condition "IsHealthBelow" (threshold: 50%)
โ โโ Selector "DefensiveActions"
โ โ โโ Action "ThrowSmokeGrenade"
โ โ โโ Action "CallForBackup"
โ โ โโ Action "TakeCoverAndHeal"
โ โโ Action "EngageFromDistance"
โ
โโ Sequence "AggressiveWhenHealthy"
โโ Condition "IsHealthAbove" (threshold: 50%)
โโ Selector "AttackPatterns"
โโ Sequence "MeleeAttack"
โ โโ Action "ChargeAtPlayer"
โ โโ Action "PerformMeleeCombo"
โโ Sequence "RangedAttack"
โโ Action "TakeAimingPosition"
โโ Action "FireWeapon"
Implementation Tips
- Use different threshold values for health conditions to create hysteresis and prevent rapid switching
- Add cooldown decorators to prevent spamming abilities (e.g., call for backup only once per minute)
- Test edge cases: what happens at exactly 50% health? Ensure conditions are mutually exclusive
๐ค Robotics Tutorials
Tutorial 3: Mobile Robot Navigation with Obstacle Avoidance
Goal: Build a navigation tree for a warehouse robot that safely navigates to delivery points while avoiding obstacles and humans.
Difficulty: Advanced | Time: 40 minutes
Tree Structure
Selector "SafeNavigation"
โโ Sequence "EmergencyStop"
โ โโ Condition "IsEmergencyButtonPressed"
โ โโ Action "ImmediateStop"
โ
โโ Sequence "HumanDetected"
โ โโ Condition "IsHumanInPath"
โ โโ Action "SlowDown"
โ โโ Action "AnnouncePresence"
โ โโ Action "NavigateAroundHuman"
โ
โโ Sequence "ObstacleDetected"
โ โโ Condition "IsObstacleNearby"
โ โโ Selector "AvoidanceStrategy"
โ โ โโ Action "SteerLeft"
โ โ โโ Action "SteerRight"
โ โ โโ Action "BackUpAndReplan"
โ โโ Action "ResumePath"
โ
โโ Sequence "NormalNavigation"
โโ Action "ComputePathToGoal"
โโ Condition "PathComputed"
โโ Action "FollowPath"
โโ Condition "ReachedGoal"
Sensor Integration
In a real robot, conditions would read from sensor data:
-
IsHumanInPath: Computer vision + LiDAR fusion -
IsObstacleNearby: LiDAR point cloud analysis -
IsEmergencyButtonPressed: Digital input from hardware
ROS 2 Integration Example
# Launch file example
ros2 launch bteditor_runner bt_runner.launch.py \
--tree_file navigation_tree.xml \
--websocket_port 8765 \
--tick_rate 10
Tutorial 4: Robotic Arm Pick-and-Place
Goal: Create a manipulation tree for a 6-DOF robotic arm to pick objects from a conveyor belt and place them in bins.
Difficulty: Advanced | Time: 50 minutes
Error Handling Strategy
Manipulation has many failure modes. Wrap each major phase in retry logic:
Decorator "RetryWithBackoff" (max_attempts=3, delay=1s)
โโ Sequence "PickObject"
โโ Action "CaptureImage"
โโ Action "DetectObjectPose"
โโ Condition "ObjectDetected"
โโ Action "PlanGraspTrajectory"
โโ Action "ExecuteGraspMotion"
โโ Action "CloseGripper"
โโ Condition "ObjectSecured"
๐ญ Automation Tutorials
Tutorial 5: Automated Testing Sequence
Goal: Design a test runner that validates a complex system through multiple test scenarios with automatic recovery.
Difficulty: Intermediate | Time: 30 minutes
Parallel Test Execution
Use Parallel nodes to run independent tests simultaneously:
Parallel "RunAllTests" (success_threshold=all)
โโ Sequence "TestDatabaseConnection"
โ โโ Action "PingDatabase"
โ โโ Condition "ResponseReceived"
โ
โโ Sequence "TestAPIEndpoints"
โ โโ Action "SendHealthCheckRequest"
โ โโ Condition "StatusCode200"
โ โโ Action "ValidateResponseBody"
โ
โโ Sequence "TestMessageQueue"
โโ Action "PublishTestMessage"
โโ Action "ConsumeMessage"
โโ Condition "MessageMatches"
๐ Learning Resources
Recommended Reading
- Getting Started Guide โ Your first behavior tree in 5 minutes
- Node Types Reference โ Complete catalog of available nodes
- Reactive Control Patterns โ When to use behavior trees vs. state machines
- Robotics Patterns โ Domain-specific best practices
Video Tutorials (Coming Soon)
We're producing video versions of these tutorials. Subscribe to our YouTube channel to get notified when they're released.
Community Examples
Check out these community-contributed behavior trees:
- Chess AI: Opening book โ Middlegame evaluation โ Endgame tablebase lookup
- Smart Home Automation: Morning routine โ Energy saving mode โ Security monitoring
- Drone Delivery: Package pickup โ Route planning โ Weather adaptation โ Safe landing
Built something cool? Share your behavior tree JSON on our GitHub Discussions or tag us on social media. We feature outstanding examples in our monthly newsletter!