Skip to content

Game.Serialization.RouteWaypointSystem

Assembly:
{{ Likely compiled into the game's runtime assembly (e.g. Assembly-CSharp). If you need the exact assembly name use your decompiler or project build outputs. }}

Namespace: Game.Serialization

Type:
class

Base:
Game.Common.GameSystemBase

Summary:
{{ RouteWaypointSystem is an ECS system that collects Waypoint components and writes references (RouteWaypoint entries) into a dynamic buffer on the corresponding owner entity. It schedules a Burst-compiled IJobChunk (RouteWaypointJob) that iterates chunks containing Waypoint and Owner components, and for each waypoint it places the entity reference into the RouteWaypoint buffer of the owner at Waypoint.m_Index — expanding the buffer with default entries if needed. The system requires the query (Waypoint + Owner) to run and uses Unity's ECS type-handle / buffer-lookup machinery via an autogenerated TypeHandle struct and InternalCompilerInterface to obtain safe job-access handles. }}


Fields

  • private EntityQuery m_Query
    {{ EntityQuery used to find all entities that have Waypoint and Owner components. The query is created in OnCreate and required for the system to update. }}

  • private TypeHandle __TypeHandle
    {{ Autogenerated struct instance that stores the EntityTypeHandle, ComponentTypeHandle, ComponentTypeHandle, and BufferLookup. The system assigns these handles before scheduling the job to give the job access to the necessary component and buffer data. }}

  • private struct RouteWaypointJob (nested)
    {{ The Burst-compiled IJobChunk that contains the logic to read entities, Waypoint and Owner components, and write into the RouteWaypoint buffer on the owner entity. It contains:

  • m_EntityType: EntityTypeHandle (read-only)
  • m_WaypointType: ComponentTypeHandle (read-only)
  • m_OwnerType: ComponentTypeHandle (read-only)
  • m_RouteWaypoints: BufferLookup (read/write) The job iterates chunk rows and ensures the owner buffer has at least Waypoint.m_Index+1 length, fills intermediate entries with default(RouteWaypoint) as needed, and writes a RouteWaypoint(entity) at the proper index. }}

  • private struct TypeHandle (nested)
    {{ Autogenerated helper containing:

  • EntityTypeHandle __Unity_Entities_Entity_TypeHandle
  • ComponentTypeHandle __Game_Routes_Waypoint_RO_ComponentTypeHandle
  • ComponentTypeHandle __Game_Common_Owner_RO_ComponentTypeHandle
  • BufferLookup __Game_Routes_RouteWaypoint_RW_BufferLookup It has an __AssignHandles(ref SystemState) method that calls state.GetEntityTypeHandle(), state.GetComponentTypeHandle(isReadOnly: true) and state.GetBufferLookup(). This follows Unity's DOTS codegen patterns for safe multi-threaded access. }}

Properties

  • (none)
    {{ This system exposes no public properties. All scheduling/handles are internal to the system and job. }}

Constructors

  • public RouteWaypointSystem()
    {{ Default parameterless constructor. Marked with [Preserve] for link-time/code-stripping safety in the game's runtime. Typical Unity ECS systems provide a default constructor; initialization occurs in OnCreate and OnCreateForCompiler. }}

Methods

  • protected override void OnCreate()
    {{ Called when the system is created. It builds and assigns the EntityQuery that matches entities containing Waypoint and Owner components:
  • m_Query = GetEntityQuery(ComponentType.ReadOnly(), ComponentType.ReadOnly());
  • RequireForUpdate(m_Query) ensures the system only updates if matching entities exist. This is where the system registers what it cares about before runtime updates. }}

  • protected override void OnUpdate()
    {{ Main update method: constructs and schedules the RouteWaypointJob. The method acquires thread-safe handles via InternalCompilerInterface.GetEntityTypeHandle / GetComponentTypeHandle / GetBufferLookup using the stored __TypeHandle fields and the system's CheckedStateRef, assigns them to a RouteWaypointJob instance, and schedules the job with JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency). The job runs with BurstCompile and writes to owner RouteWaypoint buffers. base.Dependency is updated with the scheduled job handle. }}

  • protected override void OnCreateForCompiler()
    {{ Autogenerated helper used by codegen/compilers. It calls __AssignQueries and __AssignHandles to initialize query and handle fields for the system in a way that the compiler/analysis expects. This is internal plumbing for ECS code generation. }}

  • private void __AssignQueries(ref SystemState state)
    {{ Autogenerated method used to assign EntityQuery instances during compile-time initialization. In this file it creates an EntityQueryBuilder(Allocator.Temp).Dispose(); (placeholder) — real queries are created in OnCreate, and this method exists to satisfy generated code patterns. }}

  • void __AssignHandles(ref SystemState state) (on TypeHandle)
    {{ Assigns the EntityTypeHandle, ComponentTypeHandles and BufferLookup used by the job. Marked AggressiveInlining. This is called by OnCreateForCompiler to prepare the handle struct. }}

  • RouteWaypointJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    {{ Core job execution method. For each index in the chunk:

  • reads the entity, Waypoint and Owner arrays for the chunk
  • looks up the DynamicBuffer on owner.m_Owner
  • ensures the buffer length is at least waypoint.m_Index, filling missing slots with default(RouteWaypoint)
  • writes new RouteWaypoint(waypointEntity) at the index indicated by Waypoint.m_Index This logic guarantees that each owner retains a buffer of route points consistent with their waypoints. The job implements IJobChunk and has an explicit interface implementation that simply calls this Execute. }}

Usage Example

// This system is implemented as an ECS GameSystemBase and will run automatically when enabled.
// Typical mod usage is to ensure your Waypoint and Owner components are created on entities.
// Example pseudo-setup (outside the system):

// Create an owner entity and ensure it has a DynamicBuffer<RouteWaypoint>:
Entity owner = entityManager.CreateEntity(typeof(Owner), typeof(RouteWaypoint));
// Set the Owner owner index/ID appropriately (Owner likely contains an Entity/ID field)
entityManager.SetComponentData(owner, new Owner { m_Owner = owner });

// Create a waypoint entity with a Waypoint component that references an index:
Entity waypoint = entityManager.CreateEntity(typeof(Waypoint));
entityManager.SetComponentData(waypoint, new Waypoint { m_Index = 0 });

// Also assign the Owner component on the waypoint so the system can place the route waypoint:
entityManager.AddComponentData(waypoint, new Owner { m_Owner = owner });

// When RouteWaypointSystem runs (OnUpdate), it will write
// a RouteWaypoint(waypoint) into the owner's RouteWaypoint buffer at index 0.

{{ Notes: - The job is Burst-compiled for performance and uses IJobChunk to run across archetype chunks. - The system expects Owner.m_Owner to be a valid entity index/handle that has a RouteWaypoint DynamicBuffer; ensure those buffers exist before the system runs. - Buffer expansion uses default(RouteWaypoint) for gaps; if your logic depends on specific default values, initialize accordingly. - Because the system uses BufferLookup (read/write) and ComponentTypeHandle(isReadOnly: true), it schedules write access only to the buffers and reads waypoints/owners in parallel safely. }}