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

server/server - Level Loading & Game Server

Reference for `server/server.lua`. Manages level loading, mission lifecycle, physics initialization, and the loading screen. Despite the name, this is a local "server" - BeamNG runs a client-server ar

Reference for server/server.lua. Manages level loading, mission lifecycle, physics initialization, and the loading screen. Despite the name, this is a local "server" - BeamNG runs a client-server architecture even in single-player.


Exports

KeySignatureDescription
createGame(levelPath, customLoadingFunction?)Loads a level with loading screen
destroy(profiler?)Destroys the current server/level
fadeoutLoadingScreen(skipStart?)Completes loading and fades out the loading screen
M.destroy(p)(No description available)
M.fadeoutLoadingScreen(skipStart)(No description available)
M.createGamevariable(No description available)
M.loadingProgressvariable(No description available)

Internals

Level Loading Pipeline (createGameActual)

  1. Init: Enable loading screen, set $loadingLevel, normalize path, call clientPreStartMission.
  2. Datablocks: Initialize physics world, load particle data, audio profiles, player data, managed datablocks.
  3. Materials: End any existing mission, create LevelLoadingGroup, load all .cs and .json material files from level directory.
  4. Objects: Load level objects from main/ folder (scenetree format) or legacy .mis file. Create MissionCleanup group.
  5. AI Map: Trigger map.onMissionLoaded() for navgraph building.
  6. Decals: Load main.decals.json if present.
  7. Physics: Start physics simulation.
  8. Spawn: Spawn camera and player vehicle.
  9. Fadeout: Transition from loading screen to gameplay.

endMission(profiler?)

Tears down the current level:

  • Calls clientEndMission
  • Stops audio channels
  • Clears decals
  • Deletes all objects in MissionGroup
  • Cleans up MissionCleanup, LevelLoadingGroup
  • Resets mission path

destroy(profiler?)

Full server shutdown:

  • Ends mission
  • Destroys physics world
  • Deletes all datablocks
  • Increments session counter
  • Clears levelLoaded and gameConnection globals

Command Line Patching

patchLoadingContext(ldgCtx) supports -levelOffset X Y Z to apply a global translation matrix to the level during loading.


How It Works

createGame wraps the actual loading in a loading screen request via core_gamestate. The loading screen ensures UI shows progress while the heavy work runs. After loading, fadeoutLoadingScreen fires clientPostStartMission and clientStartMission hooks, then disables the loading screen.

-- Load a level
server.createGame('/levels/west_coast_usa/info.json')

-- With custom loading callback
server.createGame('/levels/gridmap/info.json', function()
  -- Custom setup before fadeout
  server.fadeoutLoadingScreen()
end)

-- Destroy current level
server.destroy()

Exported Variables

  • loadingProgress - Exported variable - initialized as loadingProgress

screenshot.lua - Screenshot System

Reference for `screenshot.lua`. Handles screenshot capture, metadata collection, format selection, and optional upload to BeamNG's media server.

serverConnection - Client-Server Connection Manager

Reference for `serverConnection.lua`. Manages the local client-server connection lifecycle, handling disconnects and the transition from loading to gameplay-ready state.

On this page

ExportsInternalsLevel Loading Pipeline (createGameActual)endMission(profiler?)destroy(profiler?)Command Line PatchingHow It WorksExported Variables