Skip to content

Game.Debug.CollapseSFXDebugSystem

Assembly: Assembly-CSharp (Cities: Skylines 2 game/mod assembly)
Namespace: Game.Debug

Type: class

Base: BaseDebugSystem

Summary: CollapseSFXDebugSystem is a debug system that visualizes building-related special effects (SFX) such as collapse and fire SFX by drawing gizmo lines in the world. It collects buildings with PrefabRef and Transform components, looks up Effect buffers on their prefab entities, compares effect types against the game's BuildingConfigurationData (collapse and fire SFX IDs) and draws vertical lines at those effect local positions transformed to world space. The work is performed in a Burst-compiled IJobChunk (CollapseSfxCoverageGizmoJob) and scheduled in parallel. The system is disabled by default and intended for debug/visualization during modding.


Fields

  • private EntityQuery m_BuildingEffectGroup
    This query selects building entities that have Building, Game.Objects.Transform and PrefabRef components and excludes Deleted/Temp. It's the main group scanned by the job to find candidate buildings to visualize.

  • private EntityQuery m_ConfigurationQuery
    Query used to fetch the singleton BuildingConfigurationData which contains prefab references/IDs for collapse and fire SFX (m_CollapseSFX, m_FireLoopSFX, m_FireSpotSFX).

  • private GizmosSystem m_GizmosSystem
    Reference to the GizmosSystem obtained from the ECS World in OnCreate. Used to get a GizmoBatcher for drawing lines from within the job and to register a writer dependency.

  • (nested) private struct CollapseSfxCoverageGizmoJob
    A Burst-compiled IJobChunk that does the per-chunk work. Important public fields inside the job:

  • EntityTypeHandle m_EntityType — for obtaining Entity arrays from the chunk.
  • ComponentTypeHandle<PrefabRef> m_PreFabRefType — read-only; reads prefab entity references.
  • ComponentTypeHandle<Game.Objects.Transform> m_TransformType — read-only; building local transforms.
  • BufferLookup<Effect> m_EffectsBuffs — read-only; used to TryGetBuffer on the prefab entity to enumerate Effect entries.
  • BuildingConfigurationData m_BuildingConfigurationData — copied into the job; used to compare effect IDs.
  • GizmoBatcher m_GizmoBatcher — used to draw gizmo lines from the job thread.

Each Effect matching the collapse SFX draws a yellow vertical line; fire SFX entries draw a red vertical line. Lines are drawn from the effect world position up 200 units.


Properties

  • None (no public properties exposed by CollapseSFXDebugSystem).

Note: The nested job uses public fields (not properties) to pass data into the job.

Constructors

  • public CollapseSFXDebugSystem()
    Default constructor. The class is marked with [Preserve] on lifecycle methods; the constructor itself is empty in the source. Typical ECS system creation occurs via World.GetOrCreateSystemManaged().

Methods

  • protected override void OnCreate()
    Creates and caches the GizmosSystem reference, builds two EntityQueries (m_BuildingEffectGroup and m_ConfigurationQuery), calls RequireForUpdate(m_BuildingEffectGroup) to ensure the system runs only when relevant entities exist, and then disables the system by default (base.Enabled = false). Marked with [Preserve]. Use this method to see how queries are composed and how the GizmosSystem is obtained.

  • protected override JobHandle OnUpdate(JobHandle inputDeps)
    Schedules the Burst-compiled CollapseSfxCoverageGizmoJob in parallel across m_BuildingEffectGroup. It:

  • Gets EntityTypeHandle, ComponentTypeHandles for PrefabRef and Transform (read-only).
  • Gets a BufferLookup (read-only).
  • Reads BuildingConfigurationData singleton from m_ConfigurationQuery.
  • Obtains a GizmoBatcher from m_GizmosSystem (which also outputs a JobHandle dependency).
  • Schedules the job with JobChunkExtensions.ScheduleParallel and combines dependencies.
  • Calls m_GizmosSystem.AddGizmosBatcherWriter(jobHandle) to register the job as a writer for the gizmo batcher.
  • Returns the combined JobHandle.

This method performs the heavy work on worker threads and uses Burst for speed. It combines and returns dependencies properly to integrate with the ECS job system.

  • private struct CollapseSfxCoverageGizmoJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    The IJobChunk Execute implementation iterates the chunk arrays for PrefabRef/Transform/Entity, attempts to retrieve an Effect buffer from the prefab entity, iterates effects, checks their m_Effect value against m_BuildingConfigurationData.m_CollapseSFX and the fire SFX IDs, computes world positions via ObjectUtils.LocalToWorld(transform, effect.m_Position) and uses m_GizmoBatcher.DrawLine to draw vertical lines (200 units high) colored yellow for collapse or red for fire.

  • void IJobChunk.Execute(...)
    Explicit interface implementation that forwards to the job's Execute method.

Notes and implementation details: - The job uses BufferLookup.TryGetBuffer(prefab, out buffer) which is safe for looking up shared effect buffers on the prefab entity. - ObjectUtils.LocalToWorld is used to transform effect local positions to world positions based on the building transform. - GizmoBatcher is passed by value to the job and must be obtained via GizmosSystem.GetGizmosBatcher(out dependency) to ensure correct dependency chaining. - System is disabled by default; enable it to visualize SFX.

Usage Example

// Enable the debug system at runtime (example)
var world = World.DefaultGameObjectInjectionWorld;
var sfxDebugSystem = world.GetExistingSystemManaged<Game.Debug.CollapseSFXDebugSystem>();
if (sfxDebugSystem != null)
{
    sfxDebugSystem.Enabled = true; // system is disabled by default
}

// The system's OnCreate registers queries and obtains GizmosSystem.
// OnUpdate schedules the CollapseSfxCoverageGizmoJob which will draw gizmo lines:
// - Yellow vertical line for collapse SFX
// - Red vertical line for fire SFX (loop or spot)

Additional tips: - Ensure BuildingConfigurationData singleton exists in the world before enabling the system; otherwise OnUpdate may fail to retrieve the needed configuration. - Because the job uses Burst and parallel chunk scheduling, avoid modifying managed objects or UnityEngine objects inside the job. Drawing is done via GizmoBatcher which is designed to be used from jobs in this context. - Use this system to inspect SFX anchor points on building prefabs while creating or debugging building effects for mods.