Gameclass

Provides global access to core game state, utilities, and operations for S&box. The `Sandbox.Game` class exposes static properties and methods to query and control the running game, such as checking if the game is running, getting your steamid, taking screenshots, and managing game sessions.

objectGame
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public static abstract sealed class Sandbox.Game

Methods8

Showing 8 methods

public static bool ChangeScene(Sandbox.SceneLoadOptions options)PUBLICSTATIC

Change the active scene and optionally bring all connected clients to the new scene (broadcast the scene change.) If we're in a networking session, then only the host can change the scene.

ParameterTypeDescription
optionsSceneLoadOptionsThe `Sandbox.SceneLoadOptions` to use which also specifies which scene to load.
Returns:boolWhether the scene was changed successfully.

public static void Close()PUBLICSTATIC

Close the current game.

Returns:void

public static Sandbox.WebSurface CreateWebSurface()PUBLICSTATIC

Create a limited web surface

Returns:WebSurface

public static void Disconnect()PUBLICSTATIC

Disconnect from the current game session

Returns:void

public static void Load(string gameIdent, bool keepClients)PUBLICSTATIC

Load a game. You can configure the new game with LaunchArguments before calling this.

ParameterTypeDescription
gameIdentstring
keepClientsbool
Returns:void

public static void SetRandomSeed(int seed)PUBLICSTATIC

Set the seed for Game.Random

ParameterTypeDescription
seedint
Returns:void

public static void TakeHighResScreenshot(int width, int height)PUBLICSTATIC

Capture a high resolution screenshot using the active scene camera.

ParameterTypeDescription
widthint
heightint
Returns:void

public static void TakeScreenshot()PUBLICSTATIC

Capture a screenshot. Saves it in Steam.

Returns:void

Properties20

Showing 20 properties

public static Sandbox.Scene Sandbox.Game.ActiveScene { get; set; }PUBLICSTATICGETSET

The current scene that is being played.

Returns:Scene

public static ulong Sandbox.Game.AppId { get; set; }PUBLICSTATICGETSET

Steam AppId of S&box.

Returns:ulong

public static bool Sandbox.Game.CheatsEnabled { get; set; }PUBLICSTATICGETSET

This has to be in Game.dll so the codegen will get generated for it

Returns:bool

public static Sandbox.CookieContainer Sandbox.Game.Cookies { get; set; }PUBLICSTATICGETSET

Allows access to the cookies for the current game. The cookies are used to store persistent data across game sessions, such as user preferences or session data. Internally the cookies are encoded to JSON and stored in a file on disk.

Returns:CookieContainer

public static string Sandbox.Game.Ident { get; set; }PUBLICSTATICGETSET

Returns the current game's ident - ie facepunch.sandbox

Returns:string

public static bool Sandbox.Game.InGame { get; set; }PUBLICSTATICGETSET

Return true if we're in a game (ie, not in the main menu)

Returns:bool

public static bool Sandbox.Game.IsClosing { get; set; }PUBLICSTATICGETSET

Set to true when the game is closing

Returns:bool

public static bool Sandbox.Game.IsEditor { get; set; }PUBLICSTATICGETSET

Returns true if the game is running with the editor enabled

Returns:bool

public static bool Sandbox.Game.IsMainMenuVisible { get; set; }PUBLICSTATICGETSET

Returns true if the main menu is visible. Note that this will work serverside too but will only return the state of the host.

Returns:bool

public static bool Sandbox.Game.IsPaused { get; set; }PUBLICSTATICGETSET

Indicates whether the game is currently paused.

Returns:bool

public static bool Sandbox.Game.IsPlaying { get; set; }PUBLICSTATICGETSET

Indicates whether the game is currently running and actively playing a scene.

Returns:bool

public static bool Sandbox.Game.IsRecordingVideo { get; set; }PUBLICSTATICGETSET

True if we're currently recording a video (using the video command, or F6)

Returns:bool

public static bool Sandbox.Game.IsRunningInVR { get; set; }PUBLICSTATICGETSET

Return true if we're running in VR

Returns:bool

public static bool Sandbox.Game.IsRunningOnHandheld { get; set; }PUBLICSTATICGETSET

Return true if we're running on a handheld device (the deck). Will always be false serverside.

Returns:bool

public static System.Random Sandbox.Game.Random { get; set; }PUBLICSTATICGETSET

A shared random that is automatically seeded on tick

Returns:Random

public static Sandbox.Internal.TypeLibrary Sandbox.Game.TypeLibrary { get; set; }PUBLICSTATICGETSET

Provides access to the global `Sandbox.Internal.TypeLibrary` for the current game context. The `TypeLibrary` is a runtime reflection system that describes types, their members, and relationships in the game and engine assemblies. It allows you to find and create types by name and id. It's basically a sandboxed version of the .net reflection system.

Returns:TypeLibrary

On this page

Methodspublic static System.Boolean ChangeScene(Sandbox.SceneLoadOptions options)public static System.Void Close()public static Sandbox.WebSurface CreateWebSurface()public static System.Void Disconnect()public static System.Void Load(System.String gameIdent, System.Boolean keepClients)public static System.Void SetRandomSeed(System.Int32 seed)public static System.Void TakeHighResScreenshot(System.Int32 width, System.Int32 height)public static System.Void TakeScreenshot()Propertiespublic static Sandbox.Scene Sandbox.Game.ActiveScene { get; set; }public static System.UInt64 Sandbox.Game.AppId { get; set; }public static System.Boolean Sandbox.Game.CheatsEnabled { get; set; }public static Sandbox.CookieContainer Sandbox.Game.Cookies { get; set; }public static System.String Sandbox.Game.Ident { get; set; }public static System.Boolean Sandbox.Game.InGame { get; set; }public static System.Boolean Sandbox.Game.IsClosing { get; set; }public static System.Boolean Sandbox.Game.IsEditor { get; set; }public static System.Boolean Sandbox.Game.IsMainMenuVisible { get; set; }public static System.Boolean Sandbox.Game.IsPaused { get; set; }public static System.Boolean Sandbox.Game.IsPlaying { get; set; }public static System.Boolean Sandbox.Game.IsRecordingVideo { get; set; }public static System.Boolean Sandbox.Game.IsRunningInVR { get; set; }public static System.Boolean Sandbox.Game.IsRunningOnHandheld { get; set; }public static Sandbox.LanguageContainer Sandbox.Game.Language { get; set; }public static Sandbox.PhysicsTraceBuilder Sandbox.Game.PhysicsTrace { get; set; }public static System.Random Sandbox.Game.Random { get; set; }public static Sandbox.SceneTrace Sandbox.Game.SceneTrace { get; set; }public static Sandbox.SteamId Sandbox.Game.SteamId { get; set; }public static Sandbox.Internal.TypeLibrary Sandbox.Game.TypeLibrary { get; set; }Metadata