RLS Studios
ProjectsPatreonCommunityDocsAbout
Join Patreon
BeamNG Modding Docs

Guides

Reference

Server CommandsGE UtilitiesGame Engine MainNavigation GraphScreenshot CaptureServerServer ConnectionSpawnpoint ManagerSimulation TimeVehicle SpawningSuspension Frequency Tester
HDR Post-ProcessingOpenXR VRRender ViewsOffscreen View Demo

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 Extensionsrender

OpenXR VR

Manages the OpenXR VR session lifecycle: toggling on/off, welcome dialog, debug ImGui panel, headset centering, state tracking, and error handling.

Manages the OpenXR VR session lifecycle: toggling on/off, welcome dialog, debug ImGui panel, headset centering, state tracking, and error handling.


Public API

FunctionSignatureDescription
M.toggle()Cycles through disabled → welcome → enabled → disabled
M.center(value)Centers the VR headset; nil = one-shot, number = hold-and-release
M.isSessionRunning() → booleanReturns whether an OpenXR session is currently active
M.restart()Disables then re-enables OpenXR
M.closeWelcome(enable)Closes welcome dialog; starts or cancels XR based on enable
M.setStateUI(stateString)Transitions to "welcome", "enabled", or "disabled"
M.stateChanged(enabled, sessionRunning, ...)C++ callback - updates all XR state fields
M.updateUI(forced)Pushes state to UI via guihooks.trigger('OpenXRStateChanged', ...)
M.errorDetected(err)Logs error and shows toast notification
M.onInit()Sets manual unload mode, reads settings
M.onSettingsChanged()Reloads settings; restarts XR if debug mode changed
M.onUpdate(...)Handles centering countdown, runs ImGui debug panel
M.state- (function)Returns current XR state table
M.stateString- (string field)Current state: "disabled", "enabled", or "welcome"

State Machine

disabled ──toggle──> welcome ──closeWelcome(true)──> enabled
   ▲                    │                                │
   │                    └──closeWelcome(false)────────────┘
   └────────────────toggle/setStateUI("disabled")────────┘

Key State Fields (M.state)

FieldTypeDescription
enabledboolXR runtime active
sessionRunningboolXR session in progress
headsetActiveboolHeadset being worn
controller0Active/1ActiveboolController tracking
systemNamestringHMD system name
renderedWidth/HeightnumberCurrent render resolution
recommendedWidth/HeightnumberRecommended render resolution
ipdnumberInter-pupillary distance (meters)
fov0hz/fov0vt/fov1hz/fov1vtnumberPer-eye field of view

Internal State

FieldTypeDescription
M.cefDialogOpenbool/nilTracks whether the CEF welcome dialog is currently open

Settings

Setting KeyTypeDescription
openXRuiEnabledboolShow UI overlay in VR
openXRuiModeintUI anchor mode (0=Room, 1=Head)
openXRwindowViewModeint2D window view (0=Empty, 1=Between eyes, 2=Left, 3=Right)
openXRdebugEnabledboolEnable debug mode (lower framerate)
openXRquadCompositionEnabledboolUse quad composition layer

How It Works

  1. User triggers toggle() or UI sends state change
  2. setStateUI("welcome") shows a confirmation dialog (checks Vulkan adapter)
  3. On confirmation, setStateUI("enabled") calls OpenXR.toggle() to start session
  4. C++ calls stateChanged(...) each frame with headset/controller state
  5. State changes are pushed to UI via guihooks.trigger('OpenXRStateChanged')
  6. center() sends recenter request to C++ OpenXR layer
  7. setStateUI("disabled") stops session and unloads extension

Usage Examples

-- Toggle VR on/off (bound to ctrl+numpad0)
extensions.render_openxr.toggle()

-- Center headset (bound to ctrl+numpad5)
extensions.render_openxr.center()

-- Check if VR is running
if extensions.render_openxr.isSessionRunning() then
  -- VR is active
end

See Also

  • Render HDR - Post-Effect Pipeline Initialization - Related reference
  • Render Views - Offscreen Camera Screenshots - Related reference
  • Render View Demo - Render View Usage Example - Related reference
  • Game Engine Overview - Guide

HDR Post-Processing

Initializes the HDR post-processing chain (bright pass, downscale, luminance, combine) on first update. Creates engine-level PostEffect objects if they don't already exist.

Render Views

Provides a utility to create offscreen render views and save them to disk. Used for programmatic screenshots from arbitrary camera positions.

On this page

Public APIState MachineKey State Fields (M.state)Internal StateSettingsHow It WorksUsage ExamplesSee Also