Game.Debug.LaneDebugSystem
Assembly: Game (game assembly)
Namespace: Game.Debug
Type: class
Base: BaseDebugSystem
Summary: LaneDebugSystem is an in-game debug system used by Cities: Skylines 2 to draw visual lane gizmos for debugging and visualization purposes. It uses Unity's Entities (ECS) + Jobs system: a Burst-compiled IJobChunk (LaneGizmoJob) traverses lane-related entities (Curve + various lane component types) and issues drawing calls to a GizmoBatcher obtained from GizmosSystem. The system exposes runtime toggleable options (Standalone/Slave/Master/Connection/Overlap/Reserved/Blockage/Condition/Signals/Priority) to control which lane features are drawn. It is intended for modders to inspect lanes, signals, reservations, overlaps, blockages, priorities and lane conditions.
Fields
-
private EntityQuery m_LaneQuery
Used to select lane entities. Built to require Lane and Curve components and exclude Deleted and Hidden entities. The query is required for update so the system only runs when lane entities are present. -
private GizmosSystem m_GizmosSystem
Reference to the GizmosSystem used to obtain a GizmoBatcher for performing batched gizmo draw calls from jobs. -
private Option m_StandaloneOption
Toggle option for drawing standalone lanes (default enabled). -
private Option m_SlaveOption
Toggle option for drawing slave lanes (default enabled). -
private Option m_MasterOption
Toggle option for drawing master lanes (default disabled). -
private Option m_ConnectionOption
Toggle option for drawing connection lanes (default disabled). -
private Option m_OverlapOption
Toggle option for drawing lane overlaps (default disabled). -
private Option m_ReservedOption
Toggle option for drawing reserved segments/objects (default enabled). -
private Option m_BlockageOption
Toggle option for drawing blocked ranges on lanes (default enabled). -
private Option m_ConditionOption
Toggle option for drawing lane condition/wear (default disabled). -
private Option m_SignalsOption
Toggle option for drawing lane signals (default disabled). -
private Option m_PriorityOption
Toggle option for drawing priority markings (default disabled). -
private TypeHandle __TypeHandle
Holds ComponentTypeHandle/BufferTypeHandle instances (wrapped) used to obtain type handles from the SystemState. Populated in internal OnCreateForCompiler helper. -
private struct LaneGizmoJob
(nested)
Burst-compiled IJobChunk which performs the actual per-chunk lane drawing logic. Reads many component types (Curve, CarLane, TrackLane, ParkingLane, PedestrianLane, ConnectionLane, MasterLane, SlaveLane, LaneReservation, LaneCondition, LaneSignal, Temp) and two buffer types (LaneObject, LaneOverlap). It uses a GizmoBatcher to issue DrawCurve, DrawFlowCurve, DrawLine, DrawArrowHead calls etc. Also contains helper methods GetSignalColor and GetPriorityColor used to determine colors for signals and priorities. -
private struct TypeHandle
(nested)
Container for ComponentTypeHandle/BufferTypeHandle fields and an __AssignHandles method which gets the handles from a SystemState. This is used to prepare type handles for the LaneGizmoJob scheduling.
Properties
- (No public properties)
This system exposes no public properties. All runtime configuration is exposed via Option fields added in OnCreate and toggled in the debug UI.
Constructors
public LaneDebugSystem()
Default constructor. Marked with [Preserve]. Simple generated constructor; actual initialization is done in OnCreate.
Methods
protected override void OnCreate()
Initializes the system:- Gets or creates the GizmosSystem reference.
- Builds m_LaneQuery to require Lane + Curve components and exclude Deleted/Hidden.
- Calls RequireForUpdate(m_LaneQuery) so the system only updates when lanes exist.
- Registers several Option toggles using AddOption(...) with defaults:
- "Standalone Lanes" (true)
- "Slave Lanes" (true)
- "Master Lanes" (false)
- "Connection Lanes" (false)
- "Draw Overlaps" (false)
- "Draw Reserved" (true)
- "Draw Blocked" (true)
- "Draw Condition" (false)
- "Draw Signals" (false)
- "Draw Priorities" (false)
-
Disables the system by default (base.Enabled = false).
-
protected override void OnUpdate()
Schedules the LaneGizmoJob for parallel execution: - Prepares LaneGizmoJob with options and component/buffer type handles obtained via InternalCompilerInterface.GetComponentTypeHandle / GetBufferTypeHandle through __TypeHandle.
- Obtains a GizmoBatcher from m_GizmosSystem (this also produces a dependency JobHandle).
- Schedules the job via JobChunkExtensions.ScheduleParallel using m_LaneQuery and existing dependencies, and combines the job dependencies with base.Dependency.
-
Registers the job handle with the GizmosSystem (AddGizmosBatcherWriter) and assigns base.Dependency = jobHandle.
-
private void __AssignQueries(ref SystemState state)
Internal helper for compiler-time initialization (empty body aside from a temporary builder in this compiled stub). Called from OnCreateForCompiler to ensure queries exist for code generation. -
protected override void OnCreateForCompiler()
Compiler-time helper that calls __AssignQueries and __TypeHandle.__AssignHandles to populate type handles for code gen. -
LaneGizmoJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
The main per-chunk execution method implemented by the nested LaneGizmoJob. It: - Gets native arrays/buffers for Curve and the lane component types present in the chunk.
- Differentiates between temp-marked chunks (render base lane visualization) and regular chunks.
- Handles CarLane, TrackLane, ParkingLane, PedestrianLane, ConnectionLane rendering and draws curves/flow curves/lines/arrowheads based on flags, lengths and the enabled options.
- Uses LaneReservation, LaneCondition, LaneSignal, LaneObject buffers and LaneOverlap buffers to draw reservations, conditions (wear), signals, overlaps and blockages with color coding.
-
Uses helper methods GetSignalColor and GetPriorityColor to select correct color for signal and priority displays.
-
LaneGizmoJob.GetSignalColor(LaneSignal laneSignal) : Color
Maps LaneSignalType to Color: - Stop => red
- SafeStop => yellow
- Yield => magenta
- Go => green
-
default => black
-
LaneGizmoJob.GetPriorityColor(CarLane carLane) : Color
Determines color based on CarLaneFlags: - Stop flag => red
- Yield flag => magenta
- RightOfWay flag => green
- Unsafe flag => yellow
-
default => cyan
-
void IJobChunk.Execute(...) (explicit interface)
Forwarding implementation that calls the job's Execute method.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_GizmosSystem = base.World.GetOrCreateSystemManaged<GizmosSystem>();
m_LaneQuery = GetEntityQuery(
ComponentType.ReadOnly<Lane>(),
ComponentType.ReadOnly<Curve>(),
ComponentType.Exclude<Deleted>(),
ComponentType.Exclude<Hidden>()
);
RequireForUpdate(m_LaneQuery);
// Add toggleable debug options shown in the in-game debug UI
m_StandaloneOption = AddOption("Standalone Lanes", defaultEnabled: true);
m_SlaveOption = AddOption("Slave Lanes", defaultEnabled: true);
m_MasterOption = AddOption("Master Lanes", defaultEnabled: false);
m_ConnectionOption = AddOption("Connection Lanes", defaultEnabled: false);
m_OverlapOption = AddOption("Draw Overlaps", defaultEnabled: false);
m_ReservedOption = AddOption("Draw Reserved", defaultEnabled: true);
m_BlockageOption = AddOption("Draw Blocked", defaultEnabled: true);
m_ConditionOption = AddOption("Draw Condition", defaultEnabled: false);
m_SignalsOption = AddOption("Draw Signals", defaultEnabled: false);
m_PriorityOption = AddOption("Draw Priorities", defaultEnabled: false);
// Keep the debug system disabled by default
base.Enabled = false;
}
Notes for modders: - To enable visual lane debugging at runtime, enable this system (e.g., set Enabled = true or toggle via debug UI). - The drawing happens inside a Burst IJobChunk — drawing calls are batched via GizmoBatcher (retrieved from GizmosSystem). Avoid modifying ECS state from inside the job. - You can toggle which lane aspects are drawn using the registered Option instances; these are exposed in the debug UI controlled by BaseDebugSystem. - If extending or reusing this system, respect the component type handles and scheduling pattern (use InternalCompilerInterface.GetComponentTypeHandle and GetBufferTypeHandle as shown).