RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

server/commands - Camera & Input Commandsge_utils - Game Engine Utility Functionsmain.lua - GE Lua Entry Point & Game Loopmap.lua - Navigation Graph (AI Road Map)screenshot.lua - Screenshot Systemserver/server - Level Loading & Game ServerserverConnection - Client-Server Connection Manager`setSpawnpoint` - Default Spawn Point Persistence`simTimeAuthority` - Simulation Time & Bullet Time Control`spawn` - Vehicle Spawning & Safe Placement`suspensionFrequencyTester` - Suspension Natural Frequency Analysis

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 Extensions

main.lua - GE Lua Entry Point & Game Loop

Reference for `main.lua`. The root entry point for the Game Engine Lua VM - sets up the runtime environment, loads core modules, defines the main update loop, and handles all lifecycle callbacks from

Reference for main.lua. The root entry point for the Game Engine Lua VM - sets up the runtime environment, loads core modules, defines the main update loop, and handles all lifecycle callbacks from C++.


Key Global Functions

Lifecycle

FunctionDescription
init(reason)Called on load/reload - initializes settings, extensions, mods
onGameEngineStartup()Called once at engine start - bootstraps everything
onLuaReloaded()Called on Ctrl+L reload
onExit()Cleanup on shutdown
onPreExit()Pre-shutdown hook

Frame Updates

FunctionDescription
update(dtReal, dtSim, dtRaw)Main frame update - runs after input, before physics
luaPreRender(dtReal, dtSim, dtRaw)Called before rendering, after physics
updateFirstFrame()One-time first frame setup

Level Loading

FunctionDescription
clientPreStartMission(levelPath)Before mission resources load
clientPostStartMission(levelPath)After level/car fully loaded
clientStartMission(levelPath)After level items loaded
clientEndMission(levelPath)Level teardown
returnToMainMenu()Disconnects and returns to menu

Vehicle Events

FunctionDescription
vehicleSpawned(vid)Vehicle creation callback
vehicleSwitched(old, new, player)Player changed vehicles
vehicleReset(vid)Vehicle reset callback
vehicleDestroyed(vid)Vehicle removal callback
vehicleActiveChanged(vid, active)Activation state change
onCouplerAttached(o1, o2, n1, n2)Trailer coupled
onCouplerDetached(o1, o2, n1, n2)Trailer decoupled

Extension Management

FunctionDescription
loadManualUnloadExtensions()Load persistent extensions
loadPresetExtensions()Load gameplay extensions
unloadAutoExtensions()Unload non-persistent extensions
setExtensionUnloadMode(ext, mode)Set "manual" or "auto" unload
endActiveGameMode(callback)Cleanly end current game mode

Internals

Startup Sequence

  1. package.path set to include lua/ge/, lua/gui/, lua/common/, etc.
  2. Core requires: luaCore, mathlib, utils, ge_utils, json, guihooks, extensions, map, settings.
  3. onGameEngineStartup() creates MainEventManager, parses CLI args, loads client core and physics.
  4. init() loads startup extensions, initializes settings, connects online services.
  5. updateFirstFrame() finalizes settings, handles CLI arguments, waits for UI ready.

Extension Categories

  • startupExtensions: ~60 core extensions (camera, input, vehicles, UI, career, etc.) - manually unloaded.
  • presetExtensions: ~50 gameplay extensions (traffic, missions, weather, etc.) - auto-unloaded between levels.
  • editorExtensions: editor_main, editor_veMain - loaded if editor is enabled.

World Ready State Machine

  • worldReadyState = -1: Not in a level
  • worldReadyState = 0: Level loading
  • worldReadyState = 1: Waiting for vehicle materials to render
  • worldReadyState = 2: Fully ready

Key Globals Set

  • vmType = 'game'
  • gameConnection - backward compatibility (not a real scene object)
  • levelLoaded - path of loaded level or nil
  • sailingTheHighSeas - piracy detection flag
  • editor - editor interface table

How It Works

The update() function is the heart of the game loop, called every frame. It ticks settings, processes input bindings, updates sim time authority, then fires onUpdate and onGuiUpdate hooks across all extensions. luaPreRender() handles map updates, draw debug hooks, and the world-ready state transition.

-- The main update loop (simplified)
function update(dtReal, dtSim, dtRaw)
  settings.settingsTick(dtReal, dtSim, dtRaw)
  extensions.core_input_bindings.updateGFX(dtRaw)
  simTimeAuthority.update(dtReal)
  extensions.hook('onUpdate', dtReal, dtSim, dtRaw)
  if be:getUpdateUIflag() then
    extensions.hook('onGuiUpdate', dtReal, dtSim, dtRaw)
  end
end

ge_utils - Game Engine Utility Functions

Reference for `ge_utils.lua`. A large collection of global utility functions loaded at GE Lua startup - scenetree access, vehicle management, object creation, TorqueScript bridge, camera helpers, and

map.lua - Navigation Graph (AI Road Map)

Reference for `map.lua`. Builds and maintains the navigation graph (navgraph) used by AI traffic, GPS routing, and mission waypoints. Loads road data from DecalRoads and manual waypoints, then process

On this page

Key Global FunctionsLifecycleFrame UpdatesLevel LoadingVehicle EventsExtension ManagementInternalsStartup SequenceExtension CategoriesWorld Ready State MachineKey Globals SetHow It Works