Game
public static abstract sealed class Game Provides global access to core game state, utilities, and operations for S&box. The 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.
Properties
| Name | Type | Description |
|---|---|---|
AppId static | UInt64 | Steam AppId of S&box. |
InGame static | Boolean | Return true if we're in a game (ie, not in the main menu) |
IsEditor static | Boolean | Returns true if the game is running with the editor enabled |
Ident static | String | Returns the current game's ident - ie facepunch.sandbox |
IsMainMenuVisible static | Boolean | Returns true if the main menu is visible. Note that this will work serverside too but will only return the state of the host. |
IsRecordingVideo static | Boolean | True if we're currently recording a video (using the video command, or F6) |
IsClosing static | Boolean | Set to true when the game is closing |
IsRunningInVR static | Boolean | Return true if we're running in VR |
IsRunningOnHandheld static | Boolean | Return true if we're running on a handheld device (the deck). Will always be false serverside. |
Random static | Random | A shared random that is automatically seeded on tick |
SteamId static | SteamId | Your SteamId |
PhysicsTrace static | PhysicsTraceBuilder | Trace against the physics in the current scene |
SceneTrace static | SceneTrace | Trace against the physics and hitboxes in the current scene |
CheatsEnabled static | Boolean | This has to be in Game.dll so the codegen will get generated for it |
TypeLibrary static | TypeLibrary | Provides access to the global 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. |
Cookies static | CookieContainer | 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. |
Language static | LanguageContainer | Lets you get translated phrases from the localization system |
IsPlaying static | Boolean | Indicates whether the game is currently running and actively playing a scene. |
IsPaused static | Boolean | Indicates whether the game is currently paused. |
ActiveScene static | Scene | The current scene that is being played. |
Methods
static Void SetRandomSeed(Int32 seed) Set the seed for Game.Random
static WebSurface CreateWebSurface() Create a limited web surface
static Void Disconnect() Disconnect from the current game session
static Void Close() Close the current game.
static Void Load(String gameIdent, Boolean keepClients) Load a game. You can configure the new game with LaunchArguments before calling this.
static Void TakeScreenshot() Capture a screenshot. Saves it in Steam.
static Void TakeHighResScreenshot(Int32 width, Int32 height) Capture a high resolution screenshot using the active scene camera.
static Boolean ChangeScene(SceneLoadOptions options) 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.
options — The SceneLoadOptions to use which also specifies which scene to load. Examples
// Check if the game is running in the editor
if (Game.IsEditor)
{
// Perform editor-specific logic
}// Take a screenshot
Game.TakeScreenshot();