Skip to content

Game.Serialization.RouteSegmentSystem

Assembly: Game
Namespace: Game.Serialization

Type: class

Base: GameSystemBase

Summary:
A compiler-generated ECS system that populates RouteSegment dynamic buffers for owner entities based on entities that hold Segment and Owner components. It schedules a Burst-compiled IJobChunk (RouteSegmentJob) to iterate matching chunks, read Segment and Owner data, and write or expand the RouteSegment buffer for the owning entity. The system requires the Segment+Owner query to be present to run and uses cached type handles for safe, efficient access from a job.


Fields

  • private Unity.Entities.EntityQuery m_Query
    Holds the EntityQuery matching entities with ComponentType.ReadOnly() and ComponentType.ReadOnly(). The query is created in OnCreate and used to schedule the chunk job.

  • private RouteSegmentSystem.TypeHandle __TypeHandle
    Cached container for the entity/component type handles and BufferLookup used when creating and scheduling the job. The nested TypeHandle struct provides an __AssignHandles method that captures type handles from a SystemState.

  • private struct RouteSegmentJob (nested)
    Contains the job data and Execute implementation. Marked with [BurstCompile]; runs as an IJobChunk to populate RouteSegment buffers.

  • private struct TypeHandle (nested)
    A small helper struct that stores:

  • EntityTypeHandle __Unity_Entities_Entity_TypeHandle (read-only)
  • ComponentTypeHandle __Game_Routes_Segment_RO_ComponentTypeHandle (read-only)
  • ComponentTypeHandle __Game_Common_Owner_RO_ComponentTypeHandle (read-only)
  • BufferLookup __Game_Routes_RouteSegment_RW_BufferLookup (read/write) and an __AssignHandles(ref SystemState) method to initialize them.

Properties

  • None (the system does not expose public properties).

Constructors

  • public RouteSegmentSystem()
    [Preserve] attribute is applied. Default constructor; no special initialization beyond the base constructor.

Methods

  • protected override void OnCreate()
    [Preserve] Called when the system is created. Builds m_Query = GetEntityQuery(ComponentType.ReadOnly(), ComponentType.ReadOnly()) and calls RequireForUpdate(m_Query) so the system only runs when matching entities exist.

  • protected override void OnUpdate()
    [Preserve] Creates and populates an instance of RouteSegmentJob with:

  • m_EntityType from InternalCompilerInterface.GetEntityTypeHandle(...)
  • m_SegmentType and m_OwnerType from InternalCompilerInterface.GetComponentTypeHandle(...)
  • m_RouteSegments from InternalCompilerInterface.GetBufferLookup(...) Then schedules the job via JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency) and assigns the returned JobHandle to base.Dependency.

  • protected override void OnCreateForCompiler()
    Used by the generated code path to assign queries and type handles at compile-time. Calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef).

  • private void __AssignQueries(ref SystemState state)
    [MethodImpl(MethodImplOptions.AggressiveInlining)] Compiler helper that currently creates and disposes an EntityQueryBuilder(Allocator.Temp). Present to satisfy generated-code initialization patterns.

  • private struct TypeHandle.__AssignHandles(ref SystemState state)
    Assigns the entity/component type handles and buffer lookup from the provided SystemState; used by OnCreateForCompiler.

  • private struct RouteSegmentJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    [BurstCompile] The chunk job implementation:

  • Reads arrays for Entity, Segment, and Owner from the chunk.
  • For each entry, obtains the DynamicBuffer for owner.m_Owner (using m_RouteSegments[owner.m_Owner]).
  • Ensures the buffer has at least segment.m_Index entries (expanding with default RouteSegment if needed).
  • Writes a new RouteSegment(entity) at position segment.m_Index. This method is also wired as the IJobChunk.Execute implementation.

Notes: - The system is marked [CompilerGenerated] at the class level. - The job uses BufferLookup (read/write) to access dynamic buffers on owner entities. - Uses InternalCompilerInterface helper calls to obtain handles in a safety-checked way.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // This is essentially what RouteSegmentSystem does to initialize itself:
    m_Query = GetEntityQuery(ComponentType.ReadOnly<Segment>(), ComponentType.ReadOnly<Owner>());
    RequireForUpdate(m_Query);
}

Additional example (how the job populates buffers — simplified):

// Inside the job: for each matching entity with Segment + Owner
var buffer = m_RouteSegments[owner.m_Owner];
if (buffer.Length > segment.m_Index)
    buffer[segment.m_Index] = new RouteSegment(entity);
else {
    while (buffer.Length < segment.m_Index) buffer.Add(default(RouteSegment));
    buffer.Add(new RouteSegment(entity));
}

Additional notes for modders: - This system is designed to run within Unity DOTS/Entities and relies on dynamic buffers (RouteSegment) being present on owner entities. - Because the work is executed in a Burst-compiled job (IJobChunk), avoid accessing managed objects or UnityEngine APIs inside the job. - If you need to alter behavior or read results produced by this system, schedule your system to run after RouteSegmentSystem or use system dependencies to ensure correct ordering.