Skip to content
Bit Quirky Behavior Trees and
State Machines

Search documentation

All topics and APIs

Close returns focus to Search.

What are you looking for?

Try a common topic or enter a complete API identifier.

Browse the reference instead

Esc closes · Tab reaches results · Enter opens the focused link

v0.6.0
Menu

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.

One mode is a single call and the next is a whole plan, which is the moment a state should be holding a tree.

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.

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.

A behavior tree canvas with the breadcrumb DocumentationStateControls, chasing, chase behavior, showing a Sequence with two action children, chase the player and report chase status.
Figure 1. Inside the chasing state. The breadcrumb keeps the machine one click away, and the tree runs only while that mode is active.
A state machine canvas with the patrolling state, a transition reading player_visible is true, and the chasing state selected, beside a right rail whose Active Update card has Source set to Behavior Tree and names chase behavior.
Figure 2. The same machine one level up. 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.

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.

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.

Full-size image