Keep going
Repeat runs one branch again and again, with an explicit rule for what finally stops it.
On this page
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 problem
Section titled “The problem”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.
When to reach for it
Section titled “When to reach for it”- 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 with3.
See it
Section titled “See it”
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.
-
Open
Assets/Platformer/Behavior/DocumentationDecorators.bqbehaviorand select the Repeat called check 3 points. -
The rail shows END POLICY with four choices: Count, Until Success, Until Failure, and Forever. This node is on Count.
-
With Count selected, a Count field appears below it, holding
3. Enter1and the decorator becomes a pass-through for one attempt; enter5and the child completes five times before the result leaves the node. -
Switch to Until Success. The count field disappears, because the child’s own result now decides when the loop ends.
-
Switch to Forever for a decision loop, then put that Repeat at the root of the tree so the whole tree keeps deciding.
EnemyPatrol.bqbehavioris the playable version of that shape: a Repeat on Forever around the patrol Sequence, running on the Platformer enemy.

How it decides
Section titled “How it decides”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
Section titled “When it goes wrong”When it goes wrong
| Symptom | Check | Fix |
|---|---|---|
| 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. |
- Give up after: put a deadline around a loop.
- Only if: stop a loop when a fact stops being true.
- Repeat reference: the policy table and its fields.