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 exampleWeatherPhenomenon
,OnFire
,AccidentSite
,InvolvedInAccident
,Destroyed
,FacingWeather
,SpectatorSite
) and excludes entities markedDeleted
orTemp
. The query is required for the system to run (RequireForUpdate is called with it in OnCreate). -
private GizmosSystem m_GizmosSystem
Reference to the game'sGizmosSystem
retrieved from the World in OnCreate. Used to obtain aGizmoBatcher
for drawing debug geometry from the scheduled job. -
private SimulationSystem m_SimulationSystem
Reference to theSimulationSystem
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-onlyComponentTypeHandle<T>
fields for fast access inside jobs. It gets initialized via__AssignHandles
during OnCreateForCompiler. -
private struct EventGizmoJob
(nested)
A burst-compiledIJobChunk
that performs the actual gizmo drawing per chunk. It contains component type handles and aGizmoBatcher
and reads the current simulation frame to decide which gizmos to draw. -
private struct TypeHandle
(nested)
Contains read-onlyComponentTypeHandle<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 inOnCreate
.
Methods
protected override void OnCreate()
Initializes the system:- Obtains references to
GizmosSystem
andSimulationSystem
from the World. - Builds the
m_EventQuery
with Any components for event types and None components forDeleted
andTemp
. - 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)
SchedulesEventGizmoJob
as a parallel JobChunk. Key behavior: - Passes the current simulation frame (
m_SimulationSystem.frameIndex
) into the job. - Gets a
GizmoBatcher
fromm_GizmosSystem.GetGizmosBatcher(out dependencies)
and combines its dependency withinputDeps
. - 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 fromOnCreateForCompiler
. The implementation here only creates and disposes anEntityQueryBuilder
(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 storedComponentTypeHandle<T>
fields by callingstate.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 usesDuration
,WeatherPhenomenon
(and optionallyInterpolatedTransform
) 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
, andDrawArrow
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.