Game.Routes.ElementSystem
Assembly: Assembly-CSharp (inferred)
Namespace: Game.Routes
Type: class
Base: Game.Common.GameSystemBase
Summary:
ElementSystem is an ECS system that inspects Route entities and their route element buffers (RouteWaypoint and RouteSegment). It runs a Burst-compiled IJobChunk (CheckRouteElementsJob) which scans waypoints and segments referenced by each Route and, when the Owner component on a waypoint/segment points back to that route entity, schedules that waypoint/segment to be marked as Deleted using a parallel EntityCommandBuffer produced by a ModificationBarrier2B. The system caches type handles in a private TypeHandle struct, requires a Route query on creation, and registers the job handle with the modification barrier for proper producer/consumer synchronization.
Fields
-
private EntityQuery m_RouteQuery
Used to query Route entities. The query is created in OnCreate with GetEntityQuery(ComponentType.ReadOnly(), ComponentType.ReadOnly ()) and passed to RequireForUpdate so the system only runs when matching entities exist. -
private ModificationBarrier2B m_ModificationBarrier
A barrier system used to create an EntityCommandBuffer (as a parallel writer) so the job can safely add the Deleted component to waypoint/segment entities from worker threads. The barrier is retrieved in OnCreate via World.GetOrCreateSystemManaged() and later used to AddJobHandleForProducer(jobHandle). -
private TypeHandle __TypeHandle
Holds cached ECS type handles used by the job: EntityTypeHandle, BufferTypeHandle, BufferTypeHandle , and ComponentLookup . The handles are assigned in __AssignHandles(ref SystemState) to minimize per-frame handle lookups.
Properties
- (none)
Constructors
public ElementSystem()
Default constructor. Marked with [Preserve] in the source to avoid stripping.
Methods
-
protected override void OnCreate()
Initializes the system: obtains the ModificationBarrier2B, builds the route query (requiring Route and Deleted components), and registers the query with RequireForUpdate so the system only updates when relevant entities exist. -
protected override void OnUpdate()
Creates and schedules the Burst-compiled CheckRouteElementsJob with JobChunkExtensions.ScheduleParallel, passing in all required type handles and a parallel EntityCommandBuffer writer from the modification barrier. The returned JobHandle is registered with the modification barrier (AddJobHandleForProducer) and stored in base.Dependency for further chaining. -
protected override void OnCreateForCompiler()
Used to ensure type handles and query assignments are prepared for generated code paths (assigns query and type handles by calling __AssignQueries and __AssignHandles). Present to satisfy generated/IL2CPP/Burst compiler expectations. -
private void __AssignQueries(ref SystemState state)
Internal helper invoked from OnCreateForCompiler; currently contains a stubbed EntityQueryBuilder(Allocator.Temp).Dispose() call — used to force query setup in compiled builds (no-op at runtime in this decompiled form). -
Nested type:
private struct TypeHandle
Contains: - EntityTypeHandle __Unity_Entities_Entity_TypeHandle
- BufferTypeHandle
__Game_Routes_RouteWaypoint_RO_BufferTypeHandle - BufferTypeHandle
__Game_Routes_RouteSegment_RO_BufferTypeHandle -
ComponentLookup
__Game_Common_Owner_RO_ComponentLookup With a method __AssignHandles(ref SystemState) that populates those handles from the SystemState. -
Nested/Burst job:
private struct CheckRouteElementsJob : IJobChunk
(BurstCompile)
Job behavior: - Reads the chunk entity array via EntityTypeHandle.
- Reads two buffer accessors: RouteWaypoint and RouteSegment.
- Reads Owner component data via ComponentLookup
(read-only). - Iterates each Route's RouteWaypoint buffer: for each waypoint entity, if Owner[waypoint].m_Owner == routeEntity, add Deleted component to that waypoint via the parallel ECB.
- Iterates each Route's RouteSegment buffer: for each segment entity (skip Entity.Null), if Owner[segment].m_Owner == routeEntity, add Deleted component to that segment via the parallel ECB.
- Uses m_CommandBuffer.AddComponent(unfilteredChunkIndex, targetEntity, default(Deleted)) to schedule deletions from worker threads.
- The job is scheduled in parallel and implemented to also explicitly satisfy the IJobChunk.Execute method signature.
Notes / Implementation details: - The job is Burst-compiled for performance. - The CommandBuffer is used in parallel; AddComponent uses the chunk index for ordering. - The Owner lookup is read-only; RouteWaypoint and RouteSegment buffer accessors are read-only. - The system uses base.CheckedStateRef and InternalCompilerInterface helpers to obtain handles that are safe with the system's state checks.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Acquire the modification barrier used to create parallel EntityCommandBuffers
m_ModificationBarrier = World.GetOrCreateSystemManaged<ModificationBarrier2B>();
// Query routes (the original code queries entities with Route and Deleted)
m_RouteQuery = GetEntityQuery(ComponentType.ReadOnly<Route>(), ComponentType.ReadOnly<Deleted>());
RequireForUpdate(m_RouteQuery);
}
Additional notes for modders: - This system is intended to automatically mark route elements (waypoints & segments) as Deleted when their Owner points back to the route entity. If you create route elements and set their Owner to point to their route, this system will detect and schedule deletion for them when appropriate. - If you add or modify Owner, RouteWaypoint, RouteSegment, or Deleted components from other systems/jobs, ensure proper dependencies so this system sees consistent state (or rely on the modification barrier synchronization). - Be careful when modifying the matching query or component types — changing the required components or access modes may alter when or whether the system runs.