Skip to content

Game.SubRouteSystem

Assembly:
Namespace: Game.Serialization

Type: class

Base: GameSystemBase

Summary:
SubRouteSystem is a compiler-generated ECS system that populates SubRoute buffers for owner entities that reference Route entities. It queries entities that have an Owner and a Route component, then schedules a Burst-compiled IJobChunk (SubNetJob) which iterates chunks, reads the Route entity and the Owner component, and appends a SubRoute entry (wrapping the route Entity) into the owner's SubRoute dynamic buffer. The system uses generated TypeHandle wrappers and InternalCompilerInterface helper calls to obtain Entity/Component/Buffer handles and is set up to run only when the configured query has matching entities. The job is scheduled via JobChunkExtensions.Schedule and executes under Burst for performance. The class also contains compiler helper methods used by the source generator / runtime.


Fields

  • private EntityQuery m_Query
    This query is created in OnCreate to select entities that contain the Owner and Route components. The system calls RequireForUpdate(m_Query) so the system only updates when matching entities exist.

  • private TypeHandle __TypeHandle
    Holds generated type handles used to obtain EntityTypeHandle, ComponentTypeHandle (read-only) and BufferLookup (read/write). The nested TypeHandle struct provides an __AssignHandles method that binds these handles to a SystemState.

  • (nested) private struct SubNetJob : IJobChunk
    A Burst-compiled job that operates on chunks. It contains:

  • EntityTypeHandle m_EntityType — used to read the Entity array for the chunk.
  • ComponentTypeHandle<Owner> m_OwnerType — read-only owner components.
  • BufferLookup<SubRoute> m_SubRoutes — a BufferLookup used to access the target SubRoute dynamic buffers by owner entity. The job's Execute reads each entity/owner in the chunk and, if the owner's SubRoute buffer exists, appends a new SubRoute(route) entry.

  • (nested) private struct TypeHandle
    Contains the generated handle fields:

  • EntityTypeHandle __Unity_Entities_Entity_TypeHandle
  • ComponentTypeHandle<Owner> __Game_Common_Owner_RO_ComponentTypeHandle
  • BufferLookup<SubRoute> __Game_Routes_SubRoute_RW_BufferLookup and a method to assign them from a SystemState.

Properties

  • None (no public properties exposed)
    This system does not expose public properties. Internally it sets base.Dependency when scheduling the job.

Constructors

  • public SubRouteSystem()
    Default parameterless constructor. Marked with [Preserve] to prevent code stripping when AOT/IL2CPP is used.

Methods

  • protected override void OnCreate()
    Creates the entity query (Owner + Route) and calls RequireForUpdate(m_Query). This ensures the system only runs when there are matching entities.

  • protected override void OnUpdate()
    Creates and populates a SubNetJob instance by obtaining EntityTypeHandle, ComponentTypeHandle and BufferLookup via InternalCompilerInterface helper calls (using the generated __TypeHandle entries). The method schedules the job via JobChunkExtensions.Schedule and assigns the returned JobHandle to base.Dependency.

  • protected override void OnCreateForCompiler()
    Compiler helper run during system creation that calls __AssignQueries (currently a no-op builder/dispose in the generated code) and __TypeHandle.__AssignHandles to bind handles to the system state.

  • private void __AssignQueries(ref SystemState state)
    Generated helper; in this file it contains an EntityQueryBuilder(Allocator.Temp).Dispose() stub (no query built here beyond the manual creation in OnCreate).

  • (nested) TypeHandle.__AssignHandles(ref SystemState state)
    Assigns the EntityTypeHandle, ComponentTypeHandle (read-only), and BufferLookup used by the job from the provided SystemState.

  • (nested) SubNetJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Iterates the chunk's entities and Owner components. For each element it:

  • reads the Route entity
  • reads the Owner component (owner.m_Owner)
  • tries to get the owner's SubRoute dynamic buffer via BufferLookup.TryGetBuffer
  • if the buffer exists, appends a new SubRoute(route) entry

The nested explicit IJobChunk.Execute implementation simply forwards to this method. The job is Burst-compiled.

Usage Example

This system runs automatically as a GameSystemBase (no manual instantiation required). Example of how another system or component might read the SubRoute buffers populated by this system:

// Example consumer system reading SubRoute buffers created by SubRouteSystem
public partial class ReadSubRoutesSystem : GameSystemBase
{
    protected override void OnUpdate()
    {
        var subRouteLookup = SystemAPI.GetBufferLookup<SubRoute>(isReadOnly: true);

        Entities.WithoutBurst().ForEach((in Owner owner) =>
        {
            if (subRouteLookup.TryGetBuffer(owner.m_Owner, out var buffer))
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    SubRoute sr = buffer[i];
                    // sr likely contains a reference to the route entity; handle as needed
                    UnityEngine.Debug.Log($"Owner {owner.m_Owner} has sub-route entity {sr.m_Route}");
                }
            }
        }).Run();
    }
}

Notes: - SubRouteSystem is Burst-compiled on its job path and uses low-level Entity/Component/Buffer handles for high-performance bulk updates. - The system relies on a SubRoute dynamic buffer type and an Owner component type; ensure those types are defined and the Owner.m_Owner field is the entity that holds the SubRoute buffer.