Skip to content

Game.UI.ErrorDialogManager

Assembly:
Assembly-CSharp

Namespace:
Game.UI

Type:
static class

Base:
None (static utility class)

Summary:
Manages in-game error dialogs for Cities: Skylines 2. Subscribes to the engine logger events (UnityLogger) to capture exceptions and warnings/errors and queues up ErrorDialog instances to be shown to the player. When an error dialog is shown it can pause the simulation (stores and restores the simulation speed). The manager supports enabling/disabling the dialog system, clearing queued dialogs, and provides helper methods to construct dialog details and actions appropriate for the current platform and game mode.


Fields

  • private static bool m_Initialized
    Tracks whether the manager has subscribed to UnityLogger events (Initialize called). Default false. Used to avoid double subscription and to correctly unsubscribe in Dispose.

  • private static bool m_Enabled = true
    Controls whether the manager will enqueue and display new error dialogs. When set to false, existing dialogs are cleared. Default true.

  • private static Queue<ErrorDialog> m_ErrorDialogs = new Queue<ErrorDialog>()
    Queue holding pending ErrorDialog instances in FIFO order. The current dialog is the item at the front of this queue.

  • private static float m_SimulationSpeed
    Temporary storage for the simulation speed used to pause/resume the SimulationSystem when dialogs are shown/cleared.

Properties

  • public static bool enabled { get; set }
    Gets or sets whether the ErrorDialogManager accepts and queues new error dialogs. When set to false the queue is cleared immediately. Use this to globally turn off showing error dialogs (for example during automated tests or headless runs).

  • [CanBeNull] public static ErrorDialog currentErrorDialog { get; }
    Returns the ErrorDialog at the front of the queue, or null if no dialogs are queued. Read-only convenience accessor for the dialog UI to display.

Constructors

  • No public constructors (static class).
    The manager is a static utility and is initialized via Initialize().

Methods

  • public static bool TryGetFirstError(out string error)
    If any error dialogs exist, returns true and sets error to a combined string of localizedMessage and errorDetails from the first queued dialog. Returns false and sets error to null when no dialogs are queued.

  • public static void DismissAllErrors()
    Dequeues all error dialogs (calls DismissCurrentErrorDialog repeatedly). After the queue is empty the simulation speed is restored.

  • public static void Initialize()
    Subscribes to UnityLogger.OnException and UnityLogger.OnWarnOrHigher events (only once). Sets m_Initialized. Call once during mod/game startup to begin capturing logs into UI dialogs.

  • public static void Clear()
    Clears all queued dialogs and resets stored simulation speed. Does not unsubscribe event handlers.

  • public static void Dispose()
    If initialized, clears queued dialogs and unsubscribes from UnityLogger events, and resets m_Initialized. Call when unloading the mod or shutting down to avoid dangling subscriptions.

  • private static void OnException(Exception e, UnityEngine.Object context)
    Event handler for exceptions reported by UnityLogger. Builds an ErrorDialog with severity Error, localized message, detailed stack trace/context and appropriate actions, and enqueues it via ShowErrorDialog.

  • private static string GetErrorDetail(Exception e, UnityEngine.Object context)
    Constructs a detailed error string including object name/type/additional info when context is provided, and extracts a stack trace via StackTraceHelper. Used by log handlers to populate errorDetails.

  • private static void OnWarnOrHigher(ILog log, Level level, string message, Exception e, UnityEngine.Object context)
    Event handler for warnings and errors. If the log shows errors in UI (or log is null) and the level is Error or higher, it builds an ErrorDialog (severity warning or error depending on level) and enqueues it.

  • private static ErrorDialog.Actions GetActions()
    Determines which set of actions to attach to a dialog depending on the runtime platform and current game mode. For example, on PlayStation it may return SaveAndContinue for in-game/editor modes; when GameManager is null it returns Quit.

  • public static void DismissCurrentErrorDialog()
    Removes the currently displayed dialog from the queue (Dequeue) and calls RestorePause() to restore simulation speed if the queue becomes empty.

  • private static void HandlePause()
    When a dialog is enqueued, stores the current SimulationSystem.selectedSpeed (if not already stored) and sets selectedSpeed to 0 to pause simulation. Uses the active World.DefaultGameObjectInjectionWorld to locate the SimulationSystem.

  • private static void RestorePause()
    If no error dialogs remain in the queue, restores the SimulationSystem.selectedSpeed to the previously stored value.

  • public static void DisplayDebugErrorDialog()
    Convenience method to enqueue a simple debug ErrorDialog (severity Error) with static messages. Useful for testing that the dialog/UI plumbing works.

  • public static void ShowErrorDialog(ErrorDialog e)
    Enqueues the provided ErrorDialog if the manager is enabled and calls HandlePause() to pause simulation. If disabled, the dialog is ignored.

Usage Example

// Typical usage in a mod or game initialization point:
public class MyModLoader
{
    public void OnEnabled()
    {
        // Start capturing errors to UI
        ErrorDialogManager.Initialize();
    }

    public void OnDisabled()
    {
        // Clean up subscriptions when unloading
        ErrorDialogManager.Dispose();
    }

    public void TestShow()
    {
        // Quick test to show a debug error dialog
        ErrorDialogManager.DisplayDebugErrorDialog();

        // Or create and show a custom dialog:
        var dlg = new ErrorDialog
        {
            severity = ErrorDialog.Severity.Error,
            localizedMessage = "My mod encountered a problem",
            errorDetails = "Detailed stack trace or info here",
            actions = ErrorDialogManagerDisplayAction() // use GetActions-like logic if needed
        };
        ErrorDialogManager.ShowErrorDialog(dlg);
    }
}

Notes and tips: - Call Initialize() once early (mod start) to ensure exceptions and errors are captured. - When disabling error dialogs (enabled = false), the manager clears any queued dialogs immediately. - The manager pauses the simulation while any dialogs are queued and restores the saved speed only when the queue is empty.