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

Keep going

Repeat runs one branch again and again, with an explicit rule for what finally stops it.

A tree that finishes is a tree that stops deciding. Repeat is the node that keeps a branch alive, with the stopping rule written on the card.

The Platformer enemy walks a route forever. Its Sequence does one lap and reports Success, which would end the tree and leave the enemy standing in place. The naive fix is a while loop in game code, and a while loop cannot be interrupted by the graph.

EnemyPatrol.bqbehavior wraps the whole patrol Sequence in a Repeat instead. The lap finishes, the Repeat starts it again, and the agent keeps making the same decision with fresh facts each time.

  • Keep a decision loop alive for the life of the agent, which is the Forever policy around a root Sequence.
  • Retry until a fact turns true: attempt the interaction with Until Success so a failed attempt is tried again next update.
  • Do something a fixed number of times, like the three patrol points in DocumentationDecorators.bqbehavior, which uses Count with 3.
Repeat with the count policy holds one child: visit the next point keeps the running pill pass after pass, and the count lives on the repeat chip above the card rather than on the card itself.
Repeat with the count policy holds one child: visit the next point keeps the running pill pass after pass, and the count lives on the repeat chip above the card rather than on the card itself.

check 3 points counts its child’s completions: one, two, three, then hands the third result to its parent. The counter lives on the running agent, so the status pill returns to the same child once per attempt.

  1. Open Assets/Platformer/Behavior/DocumentationDecorators.bqbehavior and select the Repeat called check 3 points.

  2. The rail shows END POLICY with four choices: Count, Until Success, Until Failure, and Forever. This node is on Count.

  3. With Count selected, a Count field appears below it, holding 3. Enter 1 and the decorator becomes a pass-through for one attempt; enter 5 and the child completes five times before the result leaves the node.

  4. Switch to Until Success. The count field disappears, because the child’s own result now decides when the loop ends.

  5. Switch to Forever for a decision loop, then put that Repeat at the root of the tree so the whole tree keeps deciding. EnemyPatrol.bqbehavior is the playable version of that shape: a Repeat on Forever around the patrol Sequence, running on the Platformer enemy.

Repeat decorating a patrol action with its count policy
Figure 1. The pill on the card is the decorator. One child, one policy, one counter per agent.

Repeat wraps exactly one child. Every completed attempt increments a counter stored per agent, and a Running child keeps the current attempt open.

Result

Success
Count reached its target on a successful attempt, or Until Success saw the child succeed, or a passed-through attempt result was Success.
Failure
Until Failure saw the child fail or report Blocked, or the final counted attempt failed.
Running
The child is still working, or an attempt just completed and the policy asked for another one.
End policy What it repeats What it finally returns
Count Completed attempts, until the count is reached The last attempt’s own result
Until Success Failed and Blocked attempts Success, from the attempt that succeeded
Until Failure Successful attempts Failure or Blocked, from the attempt that stopped succeeding
Forever Every completed attempt Running, until the branch above it ends or is interrupted
  • Running is never an attempt. The counter moves only when the child produces a result.
  • Interrupted, Timeout, and Authority mismatch pass straight through without counting, so a Time Limit above a Repeat still ends the branch.
  • A restart yields for the rest of the update. Without that yield, a child that succeeds instantly would spin through attempts in a single frame; with it, one restart happens per update.
  • Leaving the decorator clears its counter. The next time the branch becomes active, the count starts from zero.
  • Count must be at least 1. The authoring schema rejects zero and negatives.

When it goes wrong

SymptomCheckFix
The agent stops deciding after one pass.Look for a Repeat at the root of the tree.Wrap the root branch in a Repeat set to Forever.
A counting Repeat never finishes.Check whether the child ever produces a result rather than holding Running.Give the child a result, or add a Time Limit so a stuck attempt ends.
Until Success loops forever on a fact that will never turn true.Read the fact the child depends on while the game runs.Wrap the Repeat in a Time Limit, or use Count so the branch gives up.
The count seems to reset at random.Check whether the branch is being left and re-entered, which clears the counter by design.Keep the counter meaningful by placing the Repeat inside the branch that stays active.
The Count field is missing from the rail.Read the END POLICY selection.Choose Count. The field belongs to that policy alone.
Full-size image