Game AI & real-time strategy
Behaviour tree
Also: behavior tree, BT
A behaviour tree is a tree structure that assembles a character’s behaviour from conditions, actions and control nodes. Control nodes such as the sequence (“do all of these in order”) and the selector (“do the first one that works”) decide which branch runs right now.
Background
Behaviour trees spread through the games industry from the mid-2000s because they sidestep the weaknesses of large state machines. Instead of wiring each transition by hand, you order behaviour by priority: at the top of the selector sits “flee when hurt”, below it “attack when an enemy is visible”, and at the bottom “patrol”.
After evaluation every node reports success, failure or running. That yields routines that are easy to reuse and easy to edit graphically. Decorators extend nodes with repetition, time limits or cooldowns.
Common problems are trees that grow so large that nobody can follow the branch priorities any more, expensive conditions recomputed on every tick, and dithering between branches when a condition hovers right at its threshold.
How we do it
Our adventures have no need for a full behaviour tree, but one of its building blocks sits in every hotspot of the Wurzelwerk engine: game logic is a list of rules, each made of a condition and actions, and the first matching rule runs. That is a flat priority selector, with no tree and no running state.
An example from the engine documentation: when you use the well, the first rule checks whether the coin has already been taken and, if so, just has Toni say a line; otherwise the second rule fires and hands over the coin. Where more structure is needed, conditions nest with all, any and not, or the if action branches.
Related terms
- Finite state machine (FSM)Game AI & real-time strategyA finite state machine models behaviour as a fixed set of states with transitions between them, exactly one of which is active at any time.
- Utility AIGame AI & real-time strategyUtility AI scores every possible action for its usefulness in the current situation and picks the best one, or chooses randomly weighted by score.
- HotspotAdventure designA hotspot is an invisible region of an adventure game scene that the player clicks or taps to examine or use something.
- Data-driven designEngine & techData-driven design separates game content from code: scenes, rules and text live in data files that the engine simply executes.