RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
Flowgraph Base ModuleFlowgraph Base NodeFlowgraph Base State NodeFlowgraph Node BuilderFlowgraph GraphFlowgraph Group HelperFlowgraph LinkFlowgraph ManagerNew Node TemplateFlowgraph PinFlowgraph States ManagerFlowgraph UtilsFlowgraph Variable Storage

UI

Resources

BeamNG Game Engine Lua Cheat SheetGE Developer RecipesMCP Server Setup

// RLS.STUDIOS=true

Premium Mods for BeamNG.drive. Career systems, custom vehicles, and immersive gameplay experiences.

Index

HomeProjectsPatreon

Socials

DiscordPatreon (RLS)Patreon (Vehicles)

© 2026 RLS Studios. All rights reserved.

Modding since 2024

API ReferenceGE Extensionsflowgraph

Flowgraph States Manager

- **File:** `extensions/flowgraph/states.lua`

Overview

  • File: extensions/flowgraph/states.lua

The States manager handles the flowgraph state machine system. It builds, starts, stops, and transitions between states defined in a state graph. States are subgraphs that run independently with their own extension proxies and hooks.

Exports

Returns a constructor function function(mgr) that creates a new States instance bound to a flowgraph manager.

Key Methods

MethodSignatureDescription
init(mgr)Initialises the states manager with empty state tables.
destroy()Calls clear().
clear()Destroys all extension proxies, clears all states, and refreshes dependencies.
buildStates()Main entry point: gathers nodes/links, resolves inter-hops, builds ports, creates states.
addStateFromPortedNode(pnode)Creates a state from a processed node with its own extension proxy.
startAutoStartStates()Starts all states flagged as auto-start.
startState(id, transData)Activates a state, submits its hooks, fires onStateStarted events.
stopState(id)Deactivates a state, clears its hooks, fires onStateStopped events.
transition(sourceStateId, transitionName, transitionData, sourceNode)Queues a transition for end-of-frame resolution.
resolveTransitions()Processes all queued transitions - stops source states, starts target states.
isRunning(id) → boolChecks if a state is currently active.
getTransitionStack(id) → tableReturns the accumulated transition data for a state.
broadcastCall(functionName, ...)Calls a hook function on all active states.
broadcastCallReturn(functionName, results, ...)Calls a hook function on all states, collecting results.
hasNodeForHook(functionName) → boolChecks if any state has a node that handles a given hook.

Internals

State Structure

Each state contains:

{
  id = nodeId,           -- unique state ID (from the state node)
  depth = {...},         -- graph depth path for group-state nesting
  graph = targetGraph,   -- the subgraph this state executes
  name = "StateName",
  autoStart = bool,      -- whether to start automatically
  extProxy = proxy,      -- extension proxy for hook isolation
  active = bool,         -- current running status
  ports = {},            -- transition ports (name → {targets, stopDepth})
  transitionStack = {},  -- accumulated data passed through transitions
}

Build Pipeline

  1. gatherNodesAndLinks() - Recursively collects all nodes and links from the state graph hierarchy into flat lists.
  2. resolveInterHops() - Flattens connections through group-state connectors (entry/exit nodes) into direct "virtual links".
  3. buildPortsAndStarts() - Assigns transition ports to each state node and identifies auto-start states.
  4. addStateFromPortedNode() - Creates runtime state objects with extension proxies.

Transition Resolution

Transitions are queued during execution and resolved at frame end via a dedicated extension proxy:

  1. All queued transitions are processed to determine which states turn on/off.
  2. States exiting group-states trigger all nested states to stop.
  3. Off-states are stopped first (sorted by ID), then on-states are started.
  4. If a final exit node is reached with no new states starting, the project stops.
  5. Transition data is accumulated in each state's transitionStack.

How It Works

  1. The flowgraph manager calls buildStates() when a state graph project starts.
  2. States are built from the state graph's node/link structure, flattening group-state hierarchies.
  3. Each state gets its own extensionProxy for isolated hook management.
  4. A resolver extension proxy runs every frame to process queued transitions.
  5. State transitions are triggered by nodes calling states:transition(sourceId, name, data).
  6. The resolver stops source states and starts target states atomically at frame end.

Usage Example

-- States are managed internally by the flowgraph system.
-- Nodes trigger transitions like:
self.mgr.states:transition(stateId, "success", {score = 100})

-- Checking if a state is running:
if self.mgr.states:isRunning(someStateId) then
  -- state is active
end

-- Getting accumulated transition data:
local stack = self.mgr.states:getTransitionStack(stateId)
local score = stack.score

Key Dependencies

  • core_flowgraphManager - proxy registration and dependency management
  • newExtensionProxy() - creates isolated extension hook proxies
  • extensions.refresh() - refreshes hook routing after proxy changes

See Also

  • Flowgraph Base Module - Related reference
  • Flowgraph Base State Node - Related reference
  • Flowgraph Base Node - Related reference
  • FlowGraph Guide - Guide

Flowgraph Pin

- **File:** `extensions/flowgraph/pin.lua`

Flowgraph Utils

Utility functions for the flowgraph system.

On this page

OverviewExportsKey MethodsInternalsState StructureBuild PipelineTransition ResolutionHow It WorksUsage ExampleKey DependenciesSee Also