S&box Wiki


Console Variables (convar) are a great way to tweak and control game features or debugging tools dynamically during runtime. They can be defined and accessed through different types depending on where they are used.


  • Client: Console variable that is available on the client

  • ClientData: A property with this attribute will be made a ClientData ConVar. It will be able to be changed by the client at any time and changes will be sent to the server. The variables will be accessible on the server by name on the Client object.

  • Engine: Console variable that is available everywhere, always

  • Menu: Console variable that is available via the menu

  • Replicated: Properties with this attribute will be replicated from the server to each client. The value can only be changed by the server or the server admin, but clients can read the value at any time.

  • Server: Console variable that is available on the server


Convars must be static.

[ConVar.Client( "my_convar_name" )] public static float MyConVar { get; set; }


ClientData doesn't need to be static - you can also (optionally) store ClientData convars as a member on an Entity.

[ConVar.ClientData( "tool_current" )] public string UserToolCurrent { get; set; } = "boxgun"


// You can access it directly - but only within the same realm currentTool = UserToolCurrent; // Or via the console system currentTool = ConsoleSystem.GetValue( "tool_current" );


To access static ClientData convars on the server, you need to go through a Client object.

public override void Simulate( IClient owner ) { currentTool = owner.GetClientData( "my_convar" ); }

If your ClientData convar is a member of an entity, it can be accessed directly.

// Will always access the convar value on the client, but on the server will access // it via the entity's GetClientOwner(). If the entity has no client owner, will be null. currentTool = UserToolCurrent;