codeAPI Reference
s&box GamePreferences: ConVar-based user settings with attributes
GamePreferences API Reference
GamePreferences is a static class for defining user preferences using ConVar attributes with automatic persistence.
Type Signature
CSHARP
public static class GamePreferencesExample Properties
CSHARP
[ConVar( "sb.autoswitch", ConVarFlags.UserInfo | ConVarFlags.Saved )]
public static bool AutoSwitch { get; set; } = true;
[ConVar( "sb.fastswitch", ConVarFlags.Saved )]
public static bool FastSwitch { get; set; } = false;
[ConVar( "sb.viewbob", ConVarFlags.Saved )]
[Group( "Camera" )]
public static bool ViewBobbing { get; set; } = true;
[ConVar( "sb.screenshake", ConVarFlags.Saved )]
[Range( 0.1f, 2f ), Step( 0.1f ), Group( "Camera" )]
public static float Screenshake { get; set; } = 0.3f;Key Attributes
- [ConVar(name, flags)] - Defines a console variable. Use ConVarFlags.Saved for persistence across sessions, ConVarFlags.UserInfo for user-specific settings.
- [Group("name")] - Groups related properties together in the inspector/console.
- [Range(min, max)] - Constrains numeric values to a range (for sliders in UI).
- [Step(value)] - Defines increment step for numeric values.
Notes
- Properties with ConVarFlags.Saved are automatically persisted to disk.
- Grouped properties appear together in the settings UI.
- Range and Step attributes enable UI controls like sliders.
Was this helpful?