RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester

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 Connection

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

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


Exports

KeySignatureDescription
onCameraHandlerSetInitial()Called when the first control object is set - transitions world to ready state
disconnect(callback?, loadingScreen?)Disconnects with optional loading screen and callback
noLoadingScreenDisconnect(profiler?)Disconnect without showing loading screen (used during exit)
M.noLoadingScreenDisconnect(p)TODO: clean this up, but not call disconnectActual directly it just will result in the gamestate getting mixed messages
M.onCameraHandlerSetInitial()(No description available)
M.disconnectvariable(No description available)

Internals

onCameraHandlerSetInitial()

Called once when the camera handler is first set after level load:

  1. Enables cursor-hide-on-inactive for the canvas.
  2. Sets worldReadyState = 1 (waiting for vehicle materials to finish rendering).
  3. Fires onWorldReadyState hook.

The transition from state 1→2 happens in luaPreRender (in main.lua) once vehicle materials are ready or a 5-second timeout elapses.

disconnectActual(callback, loadingScreen, profiler)

Full disconnect sequence:

  1. be:physicsStopSimulation() - halt physics
  2. Re-enable cursor visibility on canvas
  3. Clear lighting mission variables
  4. server.destroy() - destroy level, physics world, datablocks
  5. Clear mission filename
  6. Exit loading screen if applicable
  7. Execute callback if provided

disconnect(callback, loadingScreen)

Wrapper that optionally enters a loading screen before disconnecting. Uses core_gamestate.requestEnterLoadingScreen for managed transition.


How It Works

BeamNG uses a local client-server architecture even in single-player. This module manages that connection's lifecycle. The key transition point is onCameraHandlerSetInitial, which signals that the level is loaded enough for the camera/player to become active. Disconnect tears down everything via the server module.

-- Disconnect and return to menu
serverConnection.disconnect(function()
  core_gamestate.requestGameState()
end)

-- Quick disconnect during shutdown (no loading screen)
serverConnection.noLoadingScreenDisconnect()

See Also

  • server/commands - Related reference
  • ge_utils - Related reference
  • main.lua - Related reference
  • Game Engine Overview - Guide

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

Spawnpoint Manager

Manages per-level default spawn point selection. Saves and loads the player's chosen spawn point to/from `settings/cloud/game-state.json`.

On this page

ExportsInternalsonCameraHandlerSetInitial()disconnectActual(callback, loadingScreen, profiler)disconnect(callback, loadingScreen)How It WorksSee Also