Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/facepunch/sbox-public/llms.txt

Use this file to discover all available pages before exploring further.

The Game static class is the top-level entry point for global game state in s&box. It exposes properties to check the current runtime context, methods for managing the session lifecycle, and convenience accessors for tracing and randomness that are safe to call from any component.

Properties

Runtime context

Game.InGame
bool
Returns true when a game instance is active — that is, the player is not sitting in the main menu. Equivalent to checking whether IGameInstance.Current is non-null.
Game.IsEditor
bool
Returns true when s&box is running with the editor enabled. Use this to gate editor-only logic such as gizmo drawing or inspector helpers.
Game.IsMainMenuVisible
bool
Returns true when the main menu is visible (i.e. no game instance is active). This value is available server-side but reflects the state of the host.
Game.IsRunningInVR
bool
Returns true when the VR system is active and the player is wearing a headset.
Game.IsRunningOnHandheld
bool
Returns true when running on Steam Deck. Always false server-side.
Game.IsRecordingVideo
bool
Returns true while s&box is capturing a video (video console command or F6).
Game.IsClosing
bool
Set to true just before the game closes. Useful for skipping expensive teardown work in OnDisabled / OnDestroy.

Identity

Game.AppId
ulong
The Steam App ID for s&box.
Game.Ident
string
The identifier of the currently loaded game, for example facepunch.sandbox. Empty when no game is loaded.
Game.SteamId
SteamId
The local player’s Steam ID.

Scene accessors

Game.PhysicsTrace
PhysicsTraceBuilder
Starts a physics-only trace against the current active scene’s physics world. Shorthand for Game.ActiveScene.PhysicsWorld.Trace.
Game.SceneTrace
SceneTrace
Starts a combined physics + hitbox trace against the current active scene. Shorthand for Game.ActiveScene.Trace.

Randomness

Game.Random
System.Random
A shared Random instance that is automatically re-seeded each tick. Use this rather than constructing your own Random to ensure deterministic replays.

Persistence

Game.Cookies
CookieContainer
Persistent key/value storage for the current game. Values are serialized to JSON on disk and survive restarts. Use cookies to store per-user preferences or session tokens.
Game.Language
LanguageContainer
Access to the localization system. Use it to retrieve translated phrases by key.
Game.TypeLibrary
Sandbox.Internal.TypeLibrary
The runtime reflection system for the current game context. Lets you find, inspect, and instantiate types by name or ID — a sandboxed alternative to .NET reflection.

Methods

Screenshots

Game.TakeScreenshot()
void
Captures a screenshot at the current resolution and saves it to the player’s Steam screenshots library. Also available as the screenshot console command.
Game.TakeHighResScreenshot(int width, int height)
void
Captures a high-resolution screenshot at the specified pixel dimensions using the active scene camera. Available as screenshot_highres.

Session management

Game.Load(string gameIdent, bool keepClients)
void
Loads a different game by its ident. If called while a networked session is active and keepClients is true, a reconnect message is sent to clients before the host reloads.
Game.Close()
void
Closes the current game. In the editor this exits play mode. In standalone builds it exits the application after disconnecting from any active session.
Game.Disconnect()
void
Disconnects from the current game session without exiting the application.

Randomness

Game.SetRandomSeed(int seed)
void
Sets the seed used by Game.Random. Call this at the start of a round to produce reproducible outcomes across clients.

Web

Game.CreateWebSurface()
WebSurface
Creates a sandboxed web surface. The surface is limited in what URLs it can reach.

Usage examples

// Gate editor-only drawing
if ( Game.IsEditor )
{
    Gizmo.Draw.LineSphere( WorldPosition, 32f );
}

// Check if we're in a game
if ( Game.InGame )
{
    Log.Info( $"Playing: {Game.Ident}" );
}
Game.IsEditor and Game.IsRunningOnHandheld are always false on dedicated servers. Use Networking.IsHost to check host authority instead.

Networking

Connection management, lobby creation, and Networking.IsHost.

Input

Read player actions, analog values, and keyboard state.

Build docs developers (and LLMs) love