Skip to content

Game.Debug.WaterCullingDebugSystem

Assembly:
Game (approximate — part of the game's managed code)

Namespace:
Game.Debug

Type:
class

Base:
BaseDebugSystem

Summary:
Debug helper system for visualizing water culling / water patch information in Cities: Skylines 2. It uses the HDRenderPipeline to read water patch positions when available, and can alternatively visualize the game's WaterSystem active-cell grid. Visualization is done through the GizmosSystem via a GizmoBatcher. The system exposes two toggleable debug options: "Show active water cell" (switch between HD water patches and WaterSystem active grid) and "Fixed Height" (forces drawn patch centers to a fixed Y value).

Useful when developing or debugging mod code that affects water rendering, culling, or cell activation for the game's streaming/LOD logic. Note: this system performs drawing every frame when enabled and queries engine systems and native arrays; it's intended for debug use only and can affect performance if left enabled.

Fields

  • private GizmosSystem m_GizmosSystem
    Used to obtain a GizmoBatcher for drawing debug primitives (wire rectangles, nodes, capsules, etc.). Acquired from the world in OnCreate.

  • private WaterSystem m_WaterSystem
    Reference to the game's WaterSystem; used to query active cells, cell size, grid size and active grid dimensions.

  • private TerrainSystem m_TerrainSystem
    Used for terrain positionOffset to align active-water-cell grid visualization with world coordinates.

  • private Option m_ActiveWaterCellOption
    Debug option (toggle) created via AddOption("Show active water cell", ...). When enabled, the system draws the WaterSystem active-cell grid; when disabled, it uses HDRenderPipeline water patch positions.

  • private Option m_FixedHeight
    Debug option (toggle) created via AddOption("Fixed Height", ...). When enabled, the Y coordinate of drawn patch centers is forced to a fixed value (400f) for clearer inspection.

Properties

  • None (the class exposes no public properties).

Constructors

  • public WaterCullingDebugSystem()
    Default constructor. The class has a [Preserve] attribute on lifecycle methods, and the constructor is empty in source; actual initialization happens in OnCreate.

Methods

  • protected override void OnCreate() : System.Void
    Initializes the system:
  • Calls base.OnCreate().
  • Acquires references to GizmosSystem, WaterSystem and TerrainSystem from the world via GetOrCreateSystemManaged().
  • Adds two Option entries using AddOption: "Show active water cell" and "Fixed Height" (both default to disabled).
  • Sets base.Enabled = false so the debug display is off by default. This sets up everything required for drawing in OnUpdate.

  • protected override void OnUpdate() : System.Void
    Per-frame debug logic:

  • Early returns if the current render pipeline is not an HDRenderPipeline, unless the "Show active water cell" option is used (the code checks pipeline first and returns if not HD).
  • Obtains a GizmoBatcher from GizmosSystem and completes any job dependencies (dependencies.Complete()) to ensure safe access.
  • If m_ActiveWaterCellOption.enabled is false:
    • Calls HDRenderPipeline.GetWaterPatchesPositions() to get an array of float3 describing patch centers and extra data.
    • Iterates over a fixed number of patches (the code uses local ints num = 25 and num2 = 49) and draws:
    • Wire node at the patch center.
    • Wire rectangle sized by values from the returned positions.
    • Wire capsule representing patch extents when the returned z component > 0.
    • If m_FixedHeight.enabled is true, centers are forced to y = 400f.
    • Uses color coding: blue for positive z (presumably water present or some flag), red for negative.
  • If m_ActiveWaterCellOption.enabled is true:
    • Computes cell world size from WaterSystem.GridSize * WaterSystem.CellSize.
    • Uses TerrainSystem.positionOffset to compute world-aligned centers.
    • Reads a NativeArray from m_WaterSystem.GetActive() and m_WaterSystem.m_ActiveGridSize to iterate active grid cells.
    • Draws a wire rectangle per active cell; green if the cell value > 0 (active), red otherwise. Notes:
  • dependencies.Complete() is used to make sure the GizmoBatcher and related data are safe to use on the main thread.
  • The method assumes certain array sizes from HDRenderPipeline.GetWaterPatchesPositions(); these are hard-coded in the method (num and num2). Changing pipeline internals could require updating this code.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_GizmosSystem = base.World.GetOrCreateSystemManaged<GizmosSystem>();
    m_WaterSystem = base.World.GetOrCreateSystemManaged<WaterSystem>();
    m_TerrainSystem = base.World.GetOrCreateSystemManaged<TerrainSystem>();
    m_ActiveWaterCellOption = AddOption("Show active water cell", defaultEnabled: false);
    m_FixedHeight = AddOption("Fixed Height", defaultEnabled: false);

    // Keep this debug system off by default.
    base.Enabled = false;
}

// To enable at runtime (example):
var debugSystem = world.GetOrCreateSystemManaged<Game.Debug.WaterCullingDebugSystem>();
debugSystem.Enabled = true;
debugSystem.m_ActiveWaterCellOption.enabled = true; // show WaterSystem active grid

Additional notes / tips: - This system depends on the HDRenderPipeline; if the game is running a different pipeline the HD-specific visualization will not run. - The active-cell visualization reads a NativeArray returned by WaterSystem.GetActive(). The code views it read-only and does not attempt to dispose it — follow WaterSystem's API contract (do not dispose if it's an owned/borrowed array). - Because this draws every frame, keep it disabled during normal gameplay; only enable when actively debugging water culling or streaming issues. - Colors used: - HD water patch: blue when z > 0, red otherwise. Capsules drawn for positive z values. - Active grid cells: green for active (value > 0), red for inactive. - Be careful if internal implementations of WaterSystem/HDRenderPipeline change; hard-coded counts/indices (like the 25/49 usage) may need updating.