Skip to content

Game.ClearSystem

Assembly: Assembly-CSharp (game core assembly)
Namespace: Game.Serialization

Type: public class ClearSystem

Base: GameSystemBase

Summary:
ClearSystem is a small runtime ECS system used to remove ("clear") a broad set of simulation entities from the world. On creation it builds an EntityQuery that matches entities that contain any of a list of simulation/game state components (prefab refs, water/electricity network nodes/edges, service requests, citizen/job seekers, city statistics, effects, environment data, etc.) while explicitly excluding network composition and prefab definition entities. OnUpdate it destroys all matched entities via the EntityManager. This system is typically used during serialization/load/scene-reset operations to wipe runtime state while preserving core prefab and network composition definitions. The system methods are annotated with [Preserve] to prevent stripping by build-time optimizers.


Fields

  • private Unity.Entities.EntityQuery m_ClearQuery
    Holds the EntityQuery built in OnCreate. The query uses Any = { PrefabRef, LoadedIndex, ElectricityFlowNode, ElectricityFlowEdge, WaterPipeNode, WaterPipeEdge, ServiceRequest, WaterSourceData, City, SchoolSeeker, JobSeeker, CityStatistic, ServiceBudgetData, FloodCounterData, CoordinatedMeeting, LookingForPartner, EffectInstance, AtmosphereData, BiomeData, CreationDefinition, TimeData } and None = { NetCompositionData, PrefabData }. Entities matching this query are considered runtime state to be destroyed by this system.

Properties

  • This system does not declare any public properties.

Constructors

  • public ClearSystem()
    Default parameterless constructor. Annotated with [Preserve] in the source to ensure the system is not removed by code stripping. Construction relies on GameSystemBase lifecycle (OnCreate/OnUpdate).

Methods

  • protected override void OnCreate()
    Builds the m_ClearQuery EntityQuery. The query is configured with Any = a long list of component types representing runtime simulation state (see Fields) and None = { NetCompositionData, PrefabData } to avoid deleting network composition and prefab definition entities. The method calls base.OnCreate() first. Marked with [Preserve].

  • protected override void OnUpdate()
    Destroys all entities matched by m_ClearQuery by calling base.EntityManager.DestroyEntity(m_ClearQuery). This effectively clears the runtime entities described above. Marked with [Preserve].

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // The system builds a query that will match a broad set of runtime simulation entities.
    // After this point, OnUpdate will call EntityManager.DestroyEntity(m_ClearQuery) to clear them.
}

Additional notes / tips: - The query excludes NetCompositionData and PrefabData to keep static prefab and network composition information intact while removing dynamic simulation entities — useful when resetting or loading game state. - Because DestroyEntity(EntityQuery) removes matching entities immediately, ensure this system runs at the appropriate point in the load/serialization pipeline to avoid race conditions. - The [Preserve] attributes indicate the system and its methods must be kept during Unity's managed code stripping (important for mods and AOT builds).