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
| Key | Signature | Description |
|---|---|---|
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.createGame | variable | (No description available) |
M.loadingProgress | variable | (No description available) |
Internals
Level Loading Pipeline (createGameActual)
- Init: Enable loading screen, set
$loadingLevel, normalize path, callclientPreStartMission. - Datablocks: Initialize physics world, load particle data, audio profiles, player data, managed datablocks.
- Materials: End any existing mission, create
LevelLoadingGroup, load all.csand.jsonmaterial files from level directory. - Objects: Load level objects from
main/folder (scenetree format) or legacy.misfile. CreateMissionCleanupgroup. - AI Map: Trigger
map.onMissionLoaded()for navgraph building. - Decals: Load
main.decals.jsonif present. - Physics: Start physics simulation.
- Spawn: Spawn camera and player vehicle.
- 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
levelLoadedandgameConnectionglobals
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 asloadingProgress
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.