Skip to content

Game.Debug.EventDebugSystem

Assembly:
Assembly-CSharp (game runtime assembly)

Namespace:
Game.Debug

Type:
class

Base:
BaseDebugSystem

Summary:
EventDebugSystem is a debug/drawing system used by the game to visualize event-related data (weather phenomena, accidents, fires, spectator sites, etc.) in the editor/debug view. It queries entities that have event-related components, and schedules a burst-compiled IJobChunk (EventGizmoJob) to draw gizmos (wire arcs, nodes, arrows) via the game's GizmosSystem. The system is disabled by default and intended for debugging and visualization of ECS event components in Cities: Skylines 2.


Fields

  • private EntityQuery m_EventQuery
    This EntityQuery matches entities that have any event-related components (for example WeatherPhenomenon, OnFire, AccidentSite, InvolvedInAccident, Destroyed, FacingWeather, SpectatorSite) and excludes entities marked Deleted or Temp. The query is required for the system to run (RequireForUpdate is called with it in OnCreate).

  • private GizmosSystem m_GizmosSystem
    Reference to the game's GizmosSystem retrieved from the World in OnCreate. Used to obtain a GizmoBatcher for drawing debug geometry from the scheduled job.

  • private SimulationSystem m_SimulationSystem
    Reference to the SimulationSystem retrieved from the World in OnCreate. The simulation frame index from this system (frameIndex) is passed to the job to decide event visibility based on start/end frames.

  • private TypeHandle __TypeHandle
    A private helper struct instance that stores read-only ComponentTypeHandle<T> fields for fast access inside jobs. It gets initialized via __AssignHandles during OnCreateForCompiler.

  • private struct EventGizmoJob (nested)
    A burst-compiled IJobChunk that performs the actual gizmo drawing per chunk. It contains component type handles and a GizmoBatcher and reads the current simulation frame to decide which gizmos to draw.

  • private struct TypeHandle (nested)
    Contains read-only ComponentTypeHandle<T> fields and a method __AssignHandles(ref SystemState state) which initializes all handles from the system state. Used to bridge component handles between the managed system and the scheduled job.

Properties

  • (none)
    This system does not expose public properties. It uses private fields and component type handles internally.

Constructors

  • public EventDebugSystem()
    Default constructor. No special initialization occurs here; the system initializes required references and queries in OnCreate.

Methods

  • protected override void OnCreate()
    Initializes the system:
  • Obtains references to GizmosSystem and SimulationSystem from the World.
  • Builds the m_EventQuery with Any components for event types and None components for Deleted and Temp.
  • Calls RequireForUpdate(m_EventQuery) so the system only runs when matching entities exist.
  • Disables itself by default (base.Enabled = false).

  • protected override JobHandle OnUpdate(JobHandle inputDeps)
    Schedules EventGizmoJob as a parallel JobChunk. Key behavior:

  • Passes the current simulation frame (m_SimulationSystem.frameIndex) into the job.
  • Gets a GizmoBatcher from m_GizmosSystem.GetGizmosBatcher(out dependencies) and combines its dependency with inputDeps.
  • Initializes component type handles via InternalCompilerInterface.GetComponentTypeHandle using the stored __TypeHandle fields and the system's checked state.
  • Calls JobChunkExtensions.ScheduleParallel(..., m_EventQuery, combinedDeps) to schedule the job.
  • Registers the returned job handle with m_GizmosSystem.AddGizmosBatcherWriter(jobHandle) so gizmo writes are synchronized.
  • Returns the scheduled job handle.

The scheduled job draws: - For entities with WeatherPhenomenon + Duration: wire arcs for phenomenon radius, hotspot node + hotspot radius; also, if entities have InterpolatedTransform or Transform or Curve, draws arrows/nodes at those positions. Visibility is gated by start/end frames and intensity. - For entities with Game.Objects.Transform (non-event-specific): draws an arrow from 20 units above down to the transform position. - For entities with Curve: draws an arrow at the Bezier midpoint.

  • private void __AssignQueries(ref SystemState state)
    Called from OnCreateForCompiler. The implementation here only creates and disposes an EntityQueryBuilder (placeholder pattern used by the compiler-generated systems). It exists to satisfy compiler/runtime expectations for query assignment in generated systems.

  • protected override void OnCreateForCompiler()
    Called by the runtime/compilation pipeline when constructing compiler-generated systems. Calls base implementation, assigns queries via __AssignQueries, and initializes the __TypeHandle component type handles by calling __AssignHandles with the system state.

  • private struct TypeHandle.__AssignHandles(ref SystemState state)
    Initializes all stored ComponentTypeHandle<T> fields by calling state.GetComponentTypeHandle<T>(isReadOnly: true) for each component type used by the job.

  • private struct EventGizmoJob.Execute(in ArchetypeChunk chunk, ...)
    Burst-compiled chunk execution that:

  • If the chunk has an Event component, it uses Duration, WeatherPhenomenon (and optionally InterpolatedTransform) arrays to draw weather-event-related gizmos (arcs and nodes).
  • Otherwise if the chunk has Transform, draws arrows for each transform.
  • Otherwise if the chunk has Curve, computes the Bezier midpoint and draws arrows there.
  • Uses m_GizmoBatcher.DrawWireArc, DrawWireNode, and DrawArrow to produce the debug visuals.

Usage Example

// Enable the debug system from code (for example from a debug UI or mod init)
var world = World.DefaultGameObjectInjectionWorld;
var eventDebugSystem = world.GetOrCreateSystemManaged<Game.Debug.EventDebugSystem>();
eventDebugSystem.Enabled = true;

// The system will automatically query event entities and draw gizmos each frame.
// No further per-entity setup is required, the job reads component data and uses the GizmosSystem to draw.

Additional notes: - The job is Burst-compiled and scheduled in parallel; component type handles are fetched as read-only. - The system is intended purely for visualization and debugging; enabling it at runtime will cause additional drawing work each frame. - The EventDebugSystem relies on the GizmosSystem contract: it obtains a GizmoBatcher and must register the returned job handle via AddGizmosBatcherWriter to ensure correct ordering/synchronization for drawing.