Skip to content

Game.ConnectedRouteSystem

Assembly: Game
Namespace: Game.Serialization

Type: class

Base: GameSystemBase

Summary:
ConnectedRouteSystem is a runtime ECS system that iterates all entities with a Waypoint and Connected component and appends a ConnectedRoute entry (pointing back to the waypoint) onto the buffer of the connected entity. It uses a Burst-compiled IJobChunk (ConnectedRouteJob) to perform the work in parallel and a BufferLookup to safely write to ConnectedRoute buffers. The system requires a query of Waypoint + Connected to run and uses generated type handles for efficient access.


Fields

  • private Unity.Entities.EntityQuery m_Query
    Holds the EntityQuery used to select entities that have both Waypoint and Connected components. The query is constructed in OnCreate and used to schedule the job each frame.

  • private TypeHandle __TypeHandle
    A private container struct that stores the generated EntityTypeHandle, ComponentTypeHandle (read-only) and BufferLookup (read/write). The handles are assigned from a SystemState in OnCreateForCompiler and used to initialize the job.

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

  • EntityTypeHandle m_EntityType (read-only) — to retrieve entity ids from the chunk.
  • ComponentTypeHandle m_ConnectedType (read-only) — to read Connected components.
  • BufferLookup m_ConnectedRoutes — to write to ConnectedRoute dynamic buffers on connected entities. The job iterates chunk entries, checks if the connected entity has a ConnectedRoute buffer using HasBuffer, and if so, appends a new ConnectedRoute referencing the waypoint entity.

  • private struct TypeHandle (nested)
    Holds the ECS type handles:

  • EntityTypeHandle __Unity_Entities_Entity_TypeHandle
  • ComponentTypeHandle __Game_Routes_Connected_RO_ComponentTypeHandle
  • BufferLookup __Game_Routes_ConnectedRoute_RW_BufferLookup Provides __AssignHandles(ref SystemState) to populate these handles from the system state.

Properties

  • This class exposes no public properties.

Constructors

  • public ConnectedRouteSystem()
    Default constructor. Marked with [Preserve] on the type's lifecycle methods to avoid stripping. No custom construction logic beyond base initialization.

Methods

  • [Preserve] protected override void OnCreate()
    Initializes the system: builds the EntityQuery for entities with Waypoint and Connected components and calls RequireForUpdate(m_Query) so the system only runs when matching entities exist.

  • [Preserve] protected override void OnUpdate()
    Creates and populates a ConnectedRouteJob using type handles obtained via InternalCompilerInterface.Get*Handle wrappers (using the pre-assigned __TypeHandle fields and the system's CheckedStateRef). Schedules the job with JobChunkExtensions.Schedule against m_Query and chains it into base.Dependency.

  • protected override void OnCreateForCompiler()
    Compiler/runtime helper used to assign queries and type handles when the system is created in generated code paths. Calls __AssignQueries and TypeHandle.__AssignHandles.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Internal helper that ensures any compiler-generated EntityQueryBuilder initializations are executed. In this class it creates and immediately disposes a temporary builder (placeholder pattern in generated code).

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] public void __AssignHandles(ref SystemState state) (on TypeHandle)
    Assigns the EntityTypeHandle, ComponentTypeHandle (read-only) and BufferLookup from the given SystemState. Used by OnCreateForCompiler to cache handles.

  • private struct ConnectedRouteJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Job execution: reads the Entity array for the chunk and the Connected component array; for each entry, obtains the connected entity from the Connected component and, if that connected entity has a ConnectedRoute buffer, appends a new ConnectedRoute constructed with the waypoint entity.

Notes: - The job checks m_ConnectedRoutes.HasBuffer before writing to avoid creating buffers implicitly on entities that do not expect them. - The job is Burst-compiled ([BurstCompile]) for performance. - The system relies on generated InternalCompilerInterface getters to convert stored handles to runtime handles with correct safety checks (CheckedStateRef).

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Query built in the system: Waypoint + Connected
    // The system will automatically schedule a job each update that collects
    // waypoints into the ConnectedRoute buffers of their connected entities.
}

// Typical pattern: create waypoint entities with a Connected component pointing to
// another entity that holds a DynamicBuffer<ConnectedRoute>.
// The system will append ConnectedRoute entries referencing the waypoint.