Behavior Trees or Finite State Machines

Behavior trees and finite state machines organize gameplay logic at different levels. Use a behavior tree to choose among changing priorities and fallbacks; use a finite state machine to own explicit modes and transitions.

Core difference

Behavior tree Finite state machine
Selects what action should run next. Controls which mode is active.
Traverses ordered conditions and actions. Follows explicit transitions between states.
Naturally expresses priority and fallback. Naturally expresses entry, update, and exit behavior.
Reacts through reevaluation and conditional aborts. Reacts by satisfying transition conditions.

Use a behavior tree when

  • several actions may be valid at once;
  • the left-to-right priority of choices matters;
  • failure should try another strategy;
  • a running branch must yield when a higher-priority condition changes; or
  • the logic grows by composing reusable subtrees.

Enemy decision-making is a typical example: find cover, attack, investigate a sound, search, then patrol.

Use a finite state machine when

  • the system has stable modes such as menu, loading, playing, paused, and results;
  • transitions must be explicit and inspectable;
  • each state owns clear entry and exit work; or
  • the flow is cyclical or phase-driven.

Animation controllers and match phases are typical examples.

Use both together

A behavior tree can choose the current tactical goal while an FSM controls the execution mode for that goal. For example, the tree chooses Attack, while a movement or animation state machine handles approach, aim, fire, and recovery. Keeping decision-making separate from state execution prevents either graph from absorbing responsibilities it is not good at.

Return to What Is a Behavior Tree? or build the Behavior Tree Flow example.