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
Route Distance (Flowgraph Node)Closest Road (Flowgraph Node)Custom Lua (Flowgraph Node)Distance Between (Flowgraph Node)Waypoints Distance (Flowgraph Node)File Exists (Flowgraph Node)Get First Element of Table (Flowgraph Node)Get Level Data (Flowgraph Node)Get Map Objects IDs by DynField (Flowgraph Node)Get Table Value By Key (Flowgraph Node)GHOST (Flowgraph Node)Hide Loading Screen (Flowgraph Node)Color HSV (Flowgraph Node)Line Point From Xnorm (Flowgraph Node)Load Level (Flowgraph Node)Load Project (Flowgraph Node)On Menu (Flowgraph Node)Perlin Noise (Flowgraph Node)Pop Action Map (Flowgraph Node)Get Project InfoPush Action MapRandom ColorRandom NumberRandom QuaternionRandom VectorRoad PropertiesGet Navgraph RouteRoute PositionTemplate NodeTimeTimed SequenceTo NumberTo StringWorld Editor Open

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 Extensionsflowgraphnodesutil

Custom Lua (Flowgraph Node)

- **Node Name:** `Custom Lua`

Overview

  • Node Name: Custom Lua
  • Category: repeat_instant
  • File: extensions/flowgraph/nodes/util/customLua.lua

Create a fully custom Lua node in the flowgraph editor. Provides four code slots (work, _executionStarted, _executionStopped, onPreRender) with a sandboxed environment. Supports saving/loading from a library and custom in/out pins.

Pin Schema

No fixed pins - supports custom input and output pins added by the user via the editor.

Internals

Key Methods

MethodDescription
init()Sets up empty code slots and enables custom pins
compile(code)Compiles a code slot using load() with the sandboxed environment
exec(code)Runs a compiled code slot with pcall error handling
work()Executes the work code slot
_executionStarted()Compiles all slots, then executes _executionStarted slot
_executionStopped()Executes _executionStopped slot and clears environment
onPreRender(dt, dtSim)Executes onPreRender slot
drawCustomProperties()ImGui editor with code text areas, status indicators, save/load
buildBaseEnv()Constructs the sandboxed Lua environment

Code Slots

SlotWhen Called
workEvery frame when node has active flow input
_executionStartedWhen the project starts
_executionStoppedWhen the project stops
onPreRenderBefore each render frame

Sandboxed Environment

The environment includes access to:

  • Node: self (the node instance, with self.pinIn / self.pinOut)
  • Core: map, be, FS, path, scenetree, Engine, guihooks, extensions, settings
  • Math: vec3, quat, quatFromEuler, clamp, round, lerp, smoothstep, etc.
  • Tables: pairs, ipairs, deepcopy, shallowcopy, tableKeys, tableContains
  • IO: print, dump, readFile, writeFile, jsonReadFile, jsonWriteFile
  • Drawing: debugDrawer, ColorF, ColorI
  • ImGui: im (ui_imgui)
  • All loaded extensions via refreshExtensions()

Library System

Nodes can be saved to/loaded from a persistent library stored in editor preferences (flowgraph.general.customLuaNodes).

How It Works

  1. User writes Lua code in the editor's text areas for each slot.
  2. Code is compiled with load() using the sandboxed environment - errors shown with red icon.
  3. self.pinIn and self.pinOut are accessible via self in the environment.
  4. Custom pins can be added for inputs/outputs - they're automatically serialized.
  5. Errors during execution are caught by pcall and logged to the flowgraph event system.

Usage Example

-- In the "work" code slot:
local speed = be:getObjectByID(self.pinIn.vehId.value):getVelocity():length()
self.pinOut.speed.value = speed

-- In "_executionStarted":
self.myCounter = 0

-- In "work":
self.myCounter = self.myCounter + 1
self.pinOut.count.value = self.myCounter

-- Access extensions:
local mission = gameplay_missions_missions.getMissionById("myMission")
self.pinOut.missionName.value = translateLanguage(mission.name, mission.name)

Key Dependencies

  • load() - Lua code compilation
  • buildBaseEnv() - sandboxed environment construction
  • Editor preferences - library save/load persistence

See Also

  • Route Distance (Flowgraph Node) - Related reference
  • Closest Road (Flowgraph Node) - Related reference
  • Distance Between (Flowgraph Node) - Related reference
  • FlowGraph Guide - Guide

Closest Road (Flowgraph Node)

- **Node Name:** `Closest Road`

Distance Between (Flowgraph Node)

- **Node Name:** `Distance Between`

On this page

OverviewPin SchemaInternalsKey MethodsCode SlotsSandboxed EnvironmentLibrary SystemHow It WorksUsage ExampleKey DependenciesSee Also