What Is a Behavior Tree?

A behavior tree is a way to organize the decision-making logic of an AI agent — a game enemy, an NPC, a robot — as a tree of small, reusable tasks. Instead of one giant tangle of if/else statements or a state machine that grows unmanageable, you compose simple building blocks: “try this first, fall back to that, repeat this until it succeeds.”

Behavior trees became the dominant AI architecture in games after Halo 2 popularized them in the mid-2000s, and titles like Bioshock and Spore cemented them. Today they’re built into Unreal Engine, available in Unity through popular assets, and widely used in robotics through libraries like BehaviorTree.CPP and ROS 2.

The fastest way to build an intuition is to look at one. This is a complete enemy AI:

                    ┌─────────────┐
                    │  Selector    │  "try each child until one succeeds"
                    └──────┬──────┘
        ┌──────────────────┼───────────────────┐
   ┌────┴─────┐      ┌─────┴─────┐       ┌─────┴─────┐
   │ Sequence │      │ Sequence  │       │ Sequence  │
   │ (Attack) │      │  (Chase)  │       │ (Patrol)  │
   └────┬─────┘      └─────┬─────┘       └─────┬─────┘
     ┌──┴───┐           ┌──┴────┐        ┌─────┼─────────┐
  In range? Attack   Visible? Chase   Waypoint  Wait  Next point

▶ Open this exact tree in the free editor

Reading it top-to-bottom, left-to-right: if the player is in range, attack; otherwise if the player is visible, chase; otherwise patrol. That priority ordering falls naturally out of the structure — no flags, no state transitions to wire up.

The tick: how a behavior tree “runs”

A behavior tree doesn’t run continuously. The AI system ticks the tree at some interval — every frame, every few frames, or whenever something relevant changes. On each tick, execution starts at the root and flows down through the tree.

Every node that gets ticked returns one of three statuses:

StatusMeaning
SuccessThe task finished and achieved its goal (“target reached”).
FailureThe task cannot succeed (“no path to target”).
RunningThe task needs more time (“still walking there”).

That third status, Running, is what separates behavior trees from simple decision trees: tasks can take many frames, and the tree remembers what’s in progress.

The four kinds of nodes

Almost everything in a behavior tree is one of four node categories.

1. Composites control the flow

Composite nodes have multiple children and decide which of them run, in what order:

Those two cover the vast majority of real trees. Many implementations add a Parallel composite (run children simultaneously) and memory variants (MemSequence/MemPriority) that resume from the running child instead of re-evaluating from the start each tick.

2. Decorators modify a single child

A decorator wraps exactly one child and alters its behavior or result:

3. Conditions check the world

Leaf nodes that read game or sensor state and return Success or Failure instantly: IsPlayerVisible?, HasAmmo?, IsBatteryLow?. They never return Running.

4. Actions change the world

The leaves that actually do things: MoveToTarget, PlayAnimation, FireWeapon, GraspObject. Actions commonly return Running across many ticks while they work.

Why not just use if/else or a state machine?

You can build the patrol/chase/attack enemy with nested conditionals or a finite state machine. The problems appear as the AI grows:

There are real trade-offs — we compare the two architectures honestly in Behavior Trees vs Finite State Machines.

Try it yourself

The best way to understand behavior trees is to build one. The free, no-signup behavior tree editor on this site runs in your browser and lets you create trees with sequences, selectors, decorators and your own custom action/condition nodes, then export clean JSON you can load in your engine or framework.

▶ Start with the classic “open the door” example

Where to go next

Get behavior tree patterns in your inbox

Occasional deep dives on game AI and robotics behavior trees, plus early access to new editor features. No spam, unsubscribe anytime.