Skip to content

Game.Settings.UserState

Assembly: Assembly-CSharp.dll
Namespace: Game.Settings

Type: class

Base: Setting

Summary:
Represents persistent per-user settings and state for Cities: Skylines 2. This class is saved to a file location ("UserState") (see [FileLocation("UserState")]) and stores information such as which tutorials have been shown, last opened save metadata, cloud target selection, gameplay toggles (left-hand traffic, natural disasters, unlockAll, unlimitedMoney, unlockMapTiles), and a list of "what's new" entries. It provides helpers to reset tutorials and initialize defaults.


Fields

  • This class does not declare private instance fields in this file; its data is exposed via properties.

Properties

  • public System.Collections.Generic.Dictionary<string, bool> shownTutorials { get; set; }
    Stores a dictionary mapping tutorial identifiers to whether they have been shown to the user. Used to track which in-game tutorials have already been displayed.

  • public Game.Assets.SaveGameMetadata lastSaveGameMetadata { get; set; }
    Holds metadata for the last save game (type from Game.Assets). Can be null.

  • public string lastCloudTarget { get; set; }
    The selected cloud target for saves (e.g., "Local" by default). Used to remember where the user last chose to save/load.

  • public bool leftHandTraffic { get; set; }
    Gameplay toggle indicating whether traffic drives on the left. False by default.

  • public bool naturalDisasters { get; set; }
    Gameplay toggle for enabling/disabling natural disasters. True by default.

  • public bool unlockAll { get; set; }
    Gameplay toggle to unlock all items/features. False by default.

  • public bool unlimitedMoney { get; set; }
    Gameplay toggle for unlimited money. False by default.

  • public bool unlockMapTiles { get; set; }
    Gameplay toggle to unlock map tiles. False by default.

  • [SettingsUIHidden] public System.Collections.Generic.List<string> seenWhatsNew { get; set; }
    List of identifiers for "What's New" entries the user has already seen. Marked with SettingsUIHidden so it is not shown in settings UI.

Constructors

  • public UserState()
    Initializes a new instance and calls SetDefaults() to populate default values.

Methods

  • public void ResetTutorials() : System.Void
    Clears the shownTutorials dictionary, saves the setting (via ApplyAndSave from the Setting base class), and notifies the in-game tutorial system to reset by calling: World.DefaultGameObjectInjectionWorld.GetExistingSystemManaged().OnResetTutorials(); Use this to reset tutorial state so tutorials will be shown again.

  • public override void SetDefaults() : System.Void
    Populates all properties with their default values:

  • shownTutorials = new Dictionary()
  • lastSaveGameMetadata = null
  • lastCloudTarget = GetDefaultCloudTarget() ("Local")
  • leftHandTraffic = false
  • naturalDisasters = true
  • unlockAll = false
  • unlimitedMoney = false
  • unlockMapTiles = false
  • seenWhatsNew = new List()

  • private string GetDefaultCloudTarget() : System.String
    Returns the default cloud target string ("Local"). Centralizes the default value in case it changes.

Usage Example

// Create or load user state (usually loaded by the game's settings system)
var userState = new UserState();

// Toggle a gameplay option
userState.leftHandTraffic = true;

// Mark a tutorial as shown
userState.shownTutorials["BasicRoadsTutorial"] = true;

// Persist changes using the base Setting helper (ApplyAndSave exists on Setting)
userState.ApplyAndSave();

// Reset tutorials (clears shownTutorials, saves, and notifies the TutorialSystem)
userState.ResetTutorials();

Notes: - The class is annotated with [FileLocation("UserState")], so instances are persisted under that location by the game's settings/IO system. - ResetTutorials invokes the ECS-based TutorialSystem via World.DefaultGameObjectInjectionWorld; ensure the world/system is available when calling that method (e.g., during normal gameplay).