Skip to content

Game.Serialization.SubAreaSystem

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

Type:
class

Base:
GameSystemBase

Summary:
A DOTS/ECS system that collects all entities with the Area component and an associated Owner component, and appends SubArea buffer entries to the owner entity referencing each Area entity. The work is performed in a Burst-compiled IJobChunk (SubAreaJob) that reads entity and Owner component arrays and writes to a BufferLookup for the owner entities. The system uses generated/internal type handles (EntityTypeHandle, ComponentTypeHandle, BufferLookup) and schedules the job via JobChunkExtensions.Schedule. It requires Area+Owner entities for update (RequireForUpdate).


Fields

  • private EntityQuery m_Query
    Holds the query that matches entities with the Area and Owner components. Created in OnCreate and used to schedule the chunk job.

  • private TypeHandle __TypeHandle
    Holds the generated type handle structure containing:

  • EntityTypeHandle for reading Entity instances,
  • ComponentTypeHandle<Owner> read-only handle,
  • BufferLookup<SubArea> read/write buffer lookup. The struct provides an __AssignHandles method to initialize these handles from a SystemState.

  • private struct SubAreaJob (nested)
    Burst-compiled IJobChunk that:

  • reads chunk entity array (EntityTypeHandle),
  • reads Owner components (ComponentTypeHandle),
  • writes to owners' SubArea buffers via BufferLookup. For every Area entity in a chunk it finds the owner entity (owner.m_Owner) and, if the owner has a SubArea buffer, appends a new SubArea referring to the Area entity.

  • private struct TypeHandle (nested)
    Contains the actual handle fields and the __AssignHandles(ref SystemState) method that initializes them from the SystemState.

Properties

  • None specific to this system; all data is stored in private fields and generated handles.

Constructors

  • [Preserve] public SubAreaSystem()
    Default parameterless constructor. Marked with [Preserve] to ensure it is retained by code stripping/IL2CPP. No custom initialization beyond what GameSystemBase provides; initialization is done in OnCreate and OnCreateForCompiler.

Methods

  • protected override void OnCreate()
    Initializes the EntityQuery to match entities with Area and Owner components:
  • m_Query = GetEntityQuery(ComponentType.ReadOnly<Area>(), ComponentType.ReadOnly<Owner>());
  • Calls RequireForUpdate(m_Query) so the system only updates when matching entities exist.

  • protected override void OnUpdate()
    Constructs a SubAreaJob instance, populates its handles using InternalCompilerInterface (to retrieve the runtime handles from the cached __TypeHandle), and schedules the job:

  • Uses InternalCompilerInterface.GetEntityTypeHandle, .GetComponentTypeHandle<Owner>, and .GetBufferLookup<SubArea> to obtain the actual runtime handles.
  • Schedules the job with JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency) and assigns the resulting JobHandle to base.Dependency.

  • protected override void OnCreateForCompiler()
    Compiler-time helper called to:

  • Call __AssignQueries(ref base.CheckedStateRef) to set up any generated queries (it creates/disposes an EntityQueryBuilder in this implementation).
  • Call __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to initialize the cached TypeHandle fields for the system.

  • private void __AssignQueries(ref SystemState state)
    A small generated helper that currently creates an EntityQueryBuilder(Allocator.Temp).Dispose() (placeholder pattern generated by the compiler pipeline). Present to satisfy the code-generation/compilation contract.

  • private struct TypeHandle.__AssignHandles(ref SystemState state)
    Initializes the nested TypeHandle's internal handles:

  • __Unity_Entities_Entity_TypeHandle = state.GetEntityTypeHandle();
  • __Game_Common_Owner_RO_ComponentTypeHandle = state.GetComponentTypeHandle<Owner>(isReadOnly: true);
  • __Game_Areas_SubArea_RW_BufferLookup = state.GetBufferLookup<SubArea>();

  • private struct SubAreaJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    The job's implementation:

  • Reads arrays: chunk.GetNativeArray(m_EntityType) and chunk.GetNativeArray(ref m_OwnerType).
  • Iterates entries, and for each Owner checks m_SubAreas.HasBuffer(owner.m_Owner) and if present, calls m_SubAreas[owner.m_Owner].Add(new SubArea(area));
  • There is also an explicit IJobChunk.Execute implementation that invokes this Execute overload.

Notes on threading and safety: - The job is Burst-compiled and runs as a chunk job. BufferLookup is used for concurrent buffer access to owner entities (the system assumes owners are unique per Area or concurrency is safe for the specific data layout). - The system uses InternalCompilerInterface to get runtime type handles from stored handles; this is typical for code produced by source generators / incremental compiler pipelines.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Create and require the query so the system only runs when Area+Owner entities exist
    m_Query = GetEntityQuery(ComponentType.ReadOnly<Area>(), ComponentType.ReadOnly<Owner>());
    RequireForUpdate(m_Query);
}

(At runtime OnUpdate will construct the SubAreaJob using the stored type handles and schedule it on m_Query to fill the SubArea buffers on owner entities.)