Mode switch with an inner tree
Let a state hold a whole behavior tree, so one mode runs a plan and another runs a single action.
On this page
One mode is a single call and the next is a whole plan, which is the moment a state should be holding a tree.
The problem
Section titled “The problem”Patrolling is one call. Chasing is a plan: pick a target, move, report, give up. Force both into a state machine and chasing becomes six states nobody can follow. Force both into a tree and patrolling has to re-argue its mode every time that one call comes back.
The shape
Section titled “The shape”Keep the modes in the machine, and let the mode that needs a plan host a tree.
DocumentationStateControls.bqbehavior in the Platformer sample shows it. The patrolling state runs one direct action, follow patrol. The chasing state sets its Active Update > Source to Behavior Tree, and its canvas opens into a Sequence named chase behavior with two actions under it.

chasing state. The breadcrumb keeps the machine one click away, and the tree runs only while that mode is active.
chasing has Active Update > Source on Behavior Tree, with chase behavior named as the tree it runs.The transition between them stays simple: player spotted, evaluated continuously against player_visible. An Any State transition on reset_requested sends the actor back to patrolling from wherever it is.
Nodes it uses
Section titled “Nodes it uses”- State and Entry State for the two modes.
- Hosted Behavior Tree controls to switch a state’s Active Update from actions to a tree.
- Transition with continuous evaluation, so the spot happens the moment the value changes.
- Any State for the reset that has to work from every mode.
The playable version of the same split is EnemyStateMachine.bqbehavior, whose patrolling and defeated states coordinate the enemy while EnemyPatrol.bqbehavior owns how the walk proceeds.
Reuse it
Section titled “Reuse it”Ask one question of each behavior: does it persist until something changes it, or is it settled again as soon as the current step ends? Persisting answers are states. Re-decided answers are trees. A mode whose plan has more than two steps wants a tree inside it.
- Your first state machine: build the two-state version by hand.
- A tree inside a state: the full contract, including what a hosted result means to a transition.
- Platformer chapter: the enemy this shape drives.