Behaviour Trees
689 words · 4 min read · 3 sources
A behaviour tree is a way of organising a robot's decisions as a tree of small tasks, where a parent node repeatedly asks its children to run and each child answers success, failure, or still running.
A behaviour tree organises a robot's decisions as a tree of small tasks. A signal called a tick travels down from the top, and every node answers one of three things: success, failure, or still running. Parents use those answers to decide what to try next, so complicated behaviour is built out of small, reusable pieces instead of one tangled block of rules.
🤯 Behaviour trees spread through the games industry — Halo, BioShock and Spore all used them to drive non-player characters — before robotics adopted them as a standard way to organise a robot's decisions.
🎯 Quick challenge
What are the three values a behaviour tree node can return when it is ticked?
A behaviour tree is a way of organising a robot's decisions as a tree of small tasks, where a parent node repeatedly asks its children to run and each child answers success, failure, or still running. The parent uses those answers to decide what to try next.
How it works
Everything starts with a tick — a signal sent from the root that travels down the tree to a leaf. A node that receives a tick runs its callback, and parent nodes decide whether, when and how often to pass the tick on to their children. Every node answers with one of three values: SUCCESS, FAILURE, or RUNNING, where RUNNING means the task needs more time.
That third answer is what makes the idea work for machines: driving across a building takes thirty seconds, so the node doing the driving keeps replying "running" while the rest of the tree stays ready to react. The leaves do the real work; the nodes above them only arrange it.
| Node type | Children | What it does |
|---|---|---|
| Sequence | one or more | Ticks children left to right, stopping on failure. Succeeds only if all succeed. |
| Fallback (or selector) | one or more | Ticks children in order until one succeeds. Fails only if all fail. |
| Decorator | exactly one | Changes its child's result, or ticks it repeatedly. |
| Condition | none | Asks a question about the world. Changes nothing, never returns RUNNING. |
| Action | none | Does the actual work. May finish at once or return RUNNING while it works. |
A worked example: the battery runs low mid-delivery
A robot is carrying a parcel across a hospital when its battery drops below ten per cent.
Write that as a fallback with two children. The first: check the battery is healthy → drive to the delivery point → hand over the parcel. The second: drive to the dock → charge → resume.
Nothing in the tree has to be told about the battery. The fallback ticks its first child, the battery condition returns FAILURE, that whole branch fails, and the fallback moves on to charging. Add a third branch tomorrow — call a human if charging also fails — and nothing already written changes.
Where you'll see it
Nav2, the navigation stack for ROS 2, is built on them. It uses the BehaviorTree.CPP V4 library, and its BT Navigator takes a "navigate to pose" request, walks the tree, and calls the lower-level servers that compute plans, control efforts and recoveries. Nav2's stated reasoning: a finite state machine can need dozens of states and hundreds of transitions to cover the same ground, which becomes hard to manage.
Recovery is where that pays off. Nav2's recoveries handle failures and unknown conditions — clearing a costmap spoiled by phantom obstacles, backing up or spinning out of a stuck position, alerting an operator. Each is another branch.
Why it matters
Real robots meet closed doors, dropped parcels and flat batteries, and the hard part is often not the path planning but deciding what to do when the plan fails. Behaviour trees give that decision a shape you can read and extend. Most engineers first reach for a finite state machine, which is fine for small problems; trees are what the field turned to when those problems grew.
Common questions
Are behaviour trees the same as state machines?
No. They resemble hierarchical state machines, but the main building block of a behaviour tree is a task, not a state. A tree asks "what should I try next?" where a state machine asks "where am I now?"
Do I need Nav2 to use a behaviour tree?
No. The idea belongs to no single library, and behaviour trees were widely adopted in games before robotics — Unity and Unreal both cover them as a standard feature. Nav2 is simply the best-known robotics example.
Next step: read finite state machines — the structure most robots start with, and the one behaviour trees were built to outgrow.
Next: one minute
Watch how Behaviour Trees actually works
A one-minute video, an interactive demo you can poke at, and one question to check it landed.
Watch the one-minute lesson →Plain English. Free. Unsubscribe in one click.
Keep going
Finite State Machine
A finite state machine is a model in which a robot is always in exactly one state out of a fixed list — chargi…
ConceptNav2
Nav2 is the ROS 2 navigation stack — the batteries-included framework that takes a mobile robot from "go to th…
ConceptROS2
Robot Operating System 2 — the DDS-based middleware that runs nearly every modern research and commercial robo…
Last updated · 2026-11-08
Spotted something off? Report an error →