BlueprintPseudocode guide

State Trees

A StateTree asset is written as its schema, evaluators, global tasks and states, shaped the way the tree runs rather than as a list of settings. After the two header lines, a short legend says what the forms mean at run time.

States

The State tree section is an outline: every state's name and settings, children indented under their parent. With no Selection=, a state tries its children top to bottom and enters the first whose enter if passes.

The States section has each state in full, as state Name, its children indented under it in the order the asset saved them, since selection runs in that order. A parent's tasks keep running while any child is active. Only settings that differ from the default are written, such as Selection=, Type= for a Group, Linked, LinkedAsset or Subtree state (with what a linked one points to), and disabled.

Under a state, in this order: its description as // lines, tag, weight, tick (a custom tick rate) and enter on event, then its parameters, enter if, consider, its tasks, its transitions and its child states.

// ===== State tree =====

Root
    Idle  [Selection=TryEnterState]
    Folder  [Type=Group]
    PatrolLink  [Type=Linked -> Shared, Selection=TryEnterState]
    Off  [disabled]
Shared  [Type=Subtree]

// ===== States =====

state Root

    state Idle  [Selection=TryEnterState]
        // Waits for the player
        tag Golden.Idle
        tick 0.5
        enter on event Golden.Alert

    state Folder  [Type=Group]

Tasks and evaluators

A state's tasks sit under one run together line: they start in the order listed and then run at the same time, not one after another. The line says what ends the state: until one finishes, until all finish or one fails (a state set to wait for all its tasks), or none ends the state. The global tasks' line says when the whole tree stops instead.

A task is task Name: Struct, or task Struct when it has no name; a Blueprint task shows its class. [disabled] marks a task that does not run, and [background] one whose end and failure the state ignores (a Debug Text task is, by default). Evaluators are evaluator lines in a section of their own. Under a node are the settings that differ from its default, sorted by name.

// ===== Evaluators =====

evaluator Scout: BPE_Golden
    Radius = 500.0

// ===== Global tasks =====

run together; the tree stops when one finishes
    task Banner: StateTreeDebugTextTask  [background]
        Text = running

// ===== States =====

state Root

    state Idle
        run together until all finish or one fails
            task BPT_Golden
                Speed = 2.0
            task Spare: StateTreeDelayTask  [disabled]
                Duration = 4.0

Conditions

The conditions of a state or a transition are one expression, grouped the way the runtime evaluates them: left to right, with no precedence between And and Or, and the indents of the editor's list as brackets. Each pair is AND(x, y) or OR(x, y). Each condition is a call, Name(setting), with one setting bare and two or more as Name=Value.

A state's considerations are grouped the same way, as consider, with MUL(x, y) for Multiply; there AND takes the lower score and OR the higher.

state Root
    enter if AND(OR(AND(A(0.1), B(0.2)), C(0.3)), D(0.4))

state Cheap
    weight 2.0
    consider StateTreeConstantConsideration(0.25)

Transitions

A transition is on trigger -> target. The triggers are completed, succeeded, failed, tick, event Tag and delegate. A target is the path of a state from its subtree's root, joined with /, or one of succeeded, failed, parent, next, next selectable, next parent, next selectable parent and none. In brackets: priority when it is not Normal, reactivate and disabled. Its conditions are the if line under it.

Transitions are written in the order the tree checks them: tick, event and delegate transitions first, then completed, succeeded and failed. A delayed transition has a then wait line: its condition is checked once, when the wait starts. A completion transition is taken at once at normal priority, so a priority or delay saved on one is marked (ignored).

on event Golden.Alert -> next  [priority=High]
    if StateTreeRandomCondition(0.25)
    then wait 1.0 +/- 0.5
on tick -> parent
on completed -> Root/Idle  [disabled]
on completed -> Shared/Step  [priority=High (ignored), delay=2.0 (ignored)]

Parameters

The tree's parameters are a section of their own before the evaluators, one type name = value line each, sorted by name. A state's parameters are parameter lines under it; a value a linked state overrides ends [override]. An asset saved by UE 5.4 names the tree's parameters RootParameters, and the text keeps that name.

// ===== Parameters =====

bool Alert = True
float Speed = 300.0
Actor* Target = None
Array<int> Waypoints = [1,2,3]

state PatrolLink  [Type=Linked -> Shared]
    parameter int Count = 7  [override]
    parameter string Label = patrol

Bindings

A bound property is written as Member <- Source in place of its value, and an output binding as Member -> Target. A path starts with Parameters, a node's name, or the schema's context data such as Actor, then the property names joined with .. A property bound to a function is a call to it. A binding whose target the asset no longer holds is listed under Unresolved bindings, and a source it no longer holds is <unresolved>.

task Wait: StateTreeDelayTask
    Duration <- Parameters.Speed
task Poll: StateTreeDelayTask
    Duration <- Scout.Distance
task StateTreeDebugTextTask  [background]
    ReferenceActor <- Actor
task Spare: StateTreeDelayTask
    RandomDeviation <- StateTreeMultiplyFloatPropertyFunction(Left=2.0, Right=3.0)

Colors

The state colors the asset defines are a section after the states, color Name = (R=..,G=..,B=..,A=..), sorted by name.

// ===== Colors =====

color Danger = (R=1.0,G=0.0,B=0.0,A=1.0)