Skip to content

Game.Zones.CellCheckSystem

Assembly:
Assembly-CSharp.dll (game runtime)
{{ This system is part of the game's managed code (Assembly-CSharp). If you are building a mod that references game internals, ensure you reference the correct assembly version for the target game build. }}

Namespace:
Game.Zones
{{ The class lives in the Game.Zones namespace and coordinates zone-related ECS work. }}

Type:
class
{{ CellCheckSystem is a managed System (ECS System) responsible for checking and updating zone cells / blocks. It orchestrates collection of updated bounds and scheduling of multiple jobs that compute cells, overlaps, occupancy and lot sizes. }}

Base:
GameSystemBase
{{ Inherits from GameSystemBase (game's custom system base), so it hooks into the game's world and job/dependency management. }}


Fields

  • private struct TypeHandle __TypeHandle
    {{ Holds ComponentLookup/BufferLookup/EntityTypeHandle fields for many component and buffer types used by jobs. __TypeHandle.__AssignHandles is invoked in OnCreateForCompiler to cache lookups. Modders should not modify these directly; they are used to produce ComponentLookup/BufferLookup instances when scheduling jobs. }}

  • private UpdateCollectSystem m_ZoneUpdateCollectSystem
    {{ Reference to the update collector for zones — used to get updated bounds that may affect blocks/cells. }}

  • private Game.Objects.UpdateCollectSystem m_ObjectUpdateCollectSystem
    {{ Reference to object update collector used to detect object-driven updates that may require cell re-evaluation. }}

  • private Game.Net.UpdateCollectSystem m_NetUpdateCollectSystem
    {{ Reference to network (road/rail/etc.) update collector for net-driven updates. }}

  • private Game.Areas.UpdateCollectSystem m_AreaUpdateCollectSystem
    {{ Reference to area (lots/map tiles) update collector; used for lot and map-tile updates. }}

  • private SearchSystem m_ZoneSearchSystem
    {{ The search tree for zone blocks — provides spatial queries used to find overlapping/affected blocks. }}

  • private Game.Objects.SearchSystem m_ObjectSearchSystem
    {{ Static search tree for objects; used when checking occupation/placement relative to objects. }}

  • private Game.Net.SearchSystem m_NetSearchSystem
    {{ Network search tree used by block/cell computations to check intersections with net geometry. }}

  • private Game.Areas.SearchSystem m_AreaSearchSystem
    {{ Area search tree used for area geometry checks. }}

  • private ZoneSystem m_ZonePrefabSystem
    {{ Prefab provider for zone prefabs — used to get zone definitions / geometry data. }}

  • private ModificationBarrier5 m_ModificationBarrier
    {{ Command buffer barrier used to safely enqueue entity modifications from jobs. The system uses this to get a command buffer writer for parallel jobs. }}

  • private EntityQuery m_DeletedBlocksQuery
    {{ EntityQuery used to collect archetype chunks of blocks that are marked deleted (ReadOnly + ReadOnly and Exclude) — used during occupation job to handle deletions. }}

  • private UpdateCollectSystem m_ZoneUpdateCollectSystem
    {{ (Duplicate field listed above — the class contains this single reference used to drive zone-bound updates.) }}

(Note: the TypeHandle struct itself contains many ComponentLookup and BufferLookup fields for components such as Block, Owner, Transform, EdgeGeometry, PrefabRef, various Prefab data, Cell buffers, ValidArea, VacantLot buffers, EntityTypeHandle, Updated, etc. These are assigned in __AssignHandles and used to build job data.)

Properties

  • (none public)
    {{ CellCheckSystem exposes no public properties. It is an internal game system used by the ECS update loop. If you need to interact with it from a mod, get it via World.GetExistingSystemManaged() or World.GetOrCreateSystemManaged. }}

Constructors

  • public CellCheckSystem()
    {{ Default constructor. Marked with [Preserve] attribute in class definition — the system is created by the game's world creation code. No custom initialization is performed in the constructor; initialization happens in OnCreate. }}

Methods

  • protected override void OnCreate()
    {{ Initializes the system: retrieves references to other UpdateCollectSystems, SearchSystems and ZoneSystem (prefab provider), creates the modification barrier and builds the query for deleted blocks. This is where the system wires itself into the rest of the game's systems. Modders overriding similar systems should also call base.OnCreate() to ensure correct setup. }}

  • protected override void OnUpdate()
    {{ Core runtime logic. The method checks whether any of the tracked update-collect systems have reported updates (zone updates, object updates, net updates, area updates, map tile updates). If there are updates it:

  • Creates a set of Native containers (NativeList, NativeQueue, NativeArray, NativeQuadTree readers, etc.) with TempJob lifetime.

  • Calls CollectUpdatedBlocks to populate a list of blocks/entities to process.
  • Builds job data structs for a set of jobs (BlockCellsJob, FindOverlappingBlocksJob, GroupOverlappingBlocksJob, ZoneAndOccupyCellsJob, CheckBlockOverlapJob, UpdateBlocksJob, UpdateLotSizeJob, UpdateBoundsJob).
  • Schedules those jobs with proper dependencies and passes component/buffer lookups via InternalCompilerInterface.GetComponentLookup/GetBufferLookup and EntityTypeHandle.
  • Registers job handles as readers to the relevant SearchSystems and PrefabSystem, and as producers to the ModificationBarrier and ZoneUpdateCollectSystem.
  • Ensures proper disposal of native containers with the scheduled dependency handles.
  • Updates base.Dependency to the combined handle representing work enqueued by this system.

This is a heavily multithreaded, job-driven pipeline: it sets up a dependency graph for computing cells, overlaps, occupancy and lot sizes across potentially many changed blocks. Modders should avoid direct writes to the same components while these jobs are running and should use the game's barriers and writer handles when enqueuing changes. }}

  • private JobHandle CollectUpdatedBlocks(NativeList<CellCheckHelpers.SortedEntity> updateBlocksList)
    {{ Gathers updated bounds from multiple UpdateCollectSystem instances (zones, objects, nets, lots, map tiles) and schedules per-bounds jobs to find affected blocks from the zone search tree. It uses multiple NativeQueue writers (one per source) that are later merged by a CollectBlocksJob into the provided updateBlocksList. Returns a JobHandle representing the scheduled collection work. Important for bootstrapping the main OnUpdate jobs — it returns a handle that is combined into subsequent schedules. }}

  • private void __AssignQueries(ref SystemState state)
    {{ Compiler helper that creates/initializes any EntityQuery usage in generated code. In this class it currently builds and disposes a temporary query builder (no persistent queries are defined). This method is invoked during OnCreateForCompiler. }}

  • protected override void OnCreateForCompiler()
    {{ Compiler-time initialization helper: calls __AssignQueries and invokes __TypeHandle.__AssignHandles(ref state) to populate ComponentLookup/BufferLookup/EntityTypeHandle values used later by job scheduling. This ensures the internal handle fields are valid before jobs use them. }}

  • private void <generated>... (generated methods and job wirings)
    {{ The system schedules a number of job structs defined elsewhere (CellBlockJobs.BlockCellsJob, CellCheckHelpers.FindOverlappingBlocksJob, GroupOverlappingBlocksJob, CellOccupyJobs.ZoneAndOccupyCellsJob, CellOverlapJobs.CheckBlockOverlapJob, CellCheckHelpers.UpdateBlocksJob, LotSizeJobs.UpdateLotSizeJob, LotSizeJobs.UpdateBoundsJob). These jobs rely on the component and buffer lookups provided via the TypeHandle. See the game's job definitions for details of each job's behavior. }}

Usage Example

// Example: accessing the game's CellCheckSystem from another managed system or mod code.
// NOTE: fields inside CellCheckSystem are private — interaction is limited to getting the system instance.
// Use this only if you need to query the system's existence or to add dependencies; do not modify its internals.

using Unity.Entities;

[Preserve]
public class MySystem : GameSystemBase
{
    protected override void OnCreate()
    {
        base.OnCreate();
        // Get the CellCheckSystem instance (created by the world). This does not let you call its private methods.
        var cellCheck = World.GetOrCreateSystemManaged<Game.Zones.CellCheckSystem>();
        // Example: add your job handle as a dependency if your jobs read the same search trees or prefabs.
        // cellCheck.AddDependency(myJobHandle); // (hypothetical — CellCheckSystem does not expose such API)
    }
}

{{ Additional notes for modders and maintainers:

  • Purpose and behavior: CellCheckSystem is the central orchestrator for recomputing zone cells after relevant game changes (objects, nets, lots, map tiles, zone edits). It collects updated spatial regions and schedules a multi-stage job pipeline to update cells, detect and group overlapping blocks, assign occupancy by zone prefabs, compute lot sizes and bounds, and update cell buffers and ValidArea components.

  • Safety and correctness: The system relies on ComponentLookup/BufferLookup instances created from the SystemState (via __TypeHandle), uses the game's ModificationBarrier5 to perform safe entity modifications from jobs, and registers job readers with SearchSystems so concurrent access is coordinated. When writing mods, avoid directly modifying the same components / buffers while CellCheckSystem jobs are active. Use the game's UpdateCollectSystem or schedule work after CellCheckSystem completes (observe dependencies) to avoid race conditions.

  • Performance tips: CellCheckSystem is built to operate in highly parallel fashion — it uses deferred job arrays, parallel queues, and per-chunk processing. If you extend or call into similar pipelines, prefer creating per-task native containers (TempJob) and schedule work with appropriate batch sizes. Avoid forcing synchronous waits (JobHandle.Complete) unless absolutely necessary.

  • Compatibility: The system references several game-internal types (Block, Cell, VacantLot, PrefabRef, Area geometry types, etc.). These APIs may change between game updates. When writing mods that depend on this system or related types, test across updates and use reflection/compatibility layers if needed.

  • Debugging: Use the game's logging and conditional compilation to track job handles and dependencies when diagnosing missing updates. Inspect whether UpdateCollectSystems report updates (isUpdated flags) to see why the pipeline runs or not.

}}