Skip to content

Game.Pathfind.RoutesModifiedSystem

Assembly:
{{ Unknown (not provided). Typically this is in the game/runtime assembly that contains Game.Pathfind — include the mod/game assembly name if known. }}

Namespace: Game.Pathfind

Type: class

Base: GameSystemBase

Summary:
RoutesModifiedSystem is an ECS system that watches for changes to route-related sub-elements (access lanes, route lanes, route segments and spawn locations) and translates those entity changes into pathfinding actions that are enqueued to the PathfindQueueSystem. It collects created, updated and deleted sub-elements via EntityQueries, constructs Create/Update/Delete action buffers by scheduling Burst-compiled jobs (AddPathEdgeJob, UpdatePathEdgeJob, RemovePathEdgeJob), and enqueues those actions to m_PathfindQueueSystem to be processed by the pathfinding backend. The system also supports a one-time full rebuild after game load.


Fields

  • private PathfindQueueSystem m_PathfindQueueSystem
    Reference to the game's PathfindQueueSystem. The system enqueues CreateAction, UpdateAction and DeleteAction objects here after jobs produce action buffers.

  • private EntityQuery m_CreatedSubElementQuery
    EntityQuery used to find newly created sub-elements (Created + one of AccessLane / RouteLane / Segment / SpawnLocation but excluding MailBox / LivePath / Temp).

  • private EntityQuery m_UpdatedSubElementQuery
    EntityQuery used to find updated sub-elements (Updated + same Any filter; excludes Created/Deleted/MailBox/LivePath/Temp). Also an alternative query is created for PathfindUpdated-tagged entities.

  • private EntityQuery m_DeletedSubElementQuery
    EntityQuery used to find deleted sub-elements (Deleted + same Any filter; excludes MailBox / LivePath / Temp).

  • private EntityQuery m_AllSubElementQuery
    EntityQuery used for full rebuild: matches any sub-element (AccessLane / RouteLane / Segment / SpawnLocation) and excludes MailBox / LivePath / Temp / Deleted.

  • private bool m_Loaded
    Flag set by OnGameLoaded to request a full rebuild on the next OnUpdate. GetLoaded() flips this flag and returns whether a rebuild is requested.

  • private TypeHandle __TypeHandle
    Container for the various EntityTypeHandle / ComponentTypeHandle / ComponentLookup / BufferLookup used by the scheduled jobs. Assigned in OnCreateForCompiler via __AssignHandles.


Properties

This system does not expose public properties.


Constructors

  • public RoutesModifiedSystem()
    Default parameterless constructor (marked [Preserve] in code for runtime linking). Initializes the system instance; actual initialization of queries and handles is performed in OnCreate / OnCreateForCompiler.

Methods

  • protected override void OnCreate()
    Initializes the system: obtains the PathfindQueueSystem instance, and creates the four EntityQueries used to detect created, updated, deleted and all sub-elements. This prepares the system to detect changes and schedule jobs.

  • protected override void OnCreateForCompiler()
    Called by the generated/compiled runtime to assign queries and component handles used by the jobs. It calls __AssignQueries and sets up the TypeHandle by calling __TypeHandle.__AssignHandles.

  • protected override void OnGameLoaded(Context serializationContext)
    Called when a game save finishes loading. Sets m_Loaded = true so the next OnUpdate performs a full rebuild (all sub-elements will be processed).

  • private bool GetLoaded()
    Returns true once after OnGameLoaded has been called and clears the flag. Used to trigger a full rebuild on the next update.

  • protected override void OnUpdate()
    Core logic:

  • Decides whether to run a full rebuild (m_AllSubElementQuery) or incremental processing (created/updated/deleted queries).
  • Counts matched entities for create/update/delete.
  • For each non-zero category it:
    • Allocates a corresponding Action object (CreateAction / UpdateAction / DeleteAction).
    • Asynchronously requests an archetype chunk list for the matching query, schedules a Burst IJob (AddPathEdgeJob, UpdatePathEdgeJob, RemovePathEdgeJob) to fill the action buffer with create/update/delete entries, and combines job dependencies.
    • Disposes temporary chunk lists after scheduling.
    • Enqueues the action into the PathfindQueueSystem with the job dependency that produces its data.
  • Updates base.Dependency to reflect the scheduled jobs.

  • private void __AssignQueries(ref SystemState state)
    Compiler-generated placeholder that currently only constructs an empty EntityQueryBuilder (keeps a consistent generated layout). The TypeHandle is assigned elsewhere.

  • private struct TypeHandle
    Holds EntityTypeHandle, ComponentTypeHandle, ComponentLookup and BufferLookup values for all components used by the jobs. Includes __AssignHandles(ref SystemState) which sets all handles from a SystemState. This is used to avoid re-resolving handles inside job scheduling paths.

  • Nested job - AddPathEdgeJob (BurstCompile, implements IJob)
    Iterates archetype chunks produced by the "create" query and fills a NativeArray with CreateActionData entries describing new path edges. For each entity it:

  • Determines start/middle/end PathNode(s) depending on components present (AccessLane, SpawnLocation, RouteLane, TaxiStand, TakeoffLocation, Waypoint, etc).
  • Builds a PathSpecification for spawn locations, transport stops, taxi stops or transport-line segments. Uses many helper lookups via ComponentLookup/BufferLookup for lanes, curves, prefab data and pathfind data.
  • Also processes Game.Routes.Segment components to produce transport-line segment edges between waypoints and route-owner entities. The job uses helpers defined within the structure (GetSpawnLocationData, GetRouteConnectionData, GetTransportLineData, GetTransportLinePathfindData, GetNetLaneTransportPathfindData, GetSpawnLocationPathSpecification) that use the provided ComponentLookup/PrefabRef caches to convert prefab and lane data into PathSpecification values.

  • Nested job - UpdatePathEdgeJob (BurstCompile, implements IJob)
    Very similar to AddPathEdgeJob but fills NativeArray for updated sub-elements. The logic mirrors AddPathEdgeJob: determine nodes, build Location and Specification, and append UpdateActionData entries for segments as well.

  • Nested job - RemovePathEdgeJob (BurstCompile, implements IJob)
    Simple job that iterates entities in archetype chunks from the deletion query and writes DeleteActionData entries (owner only) into a NativeArray. Used to remove path edges owned by deleted sub-elements.

  • Helper methods inside jobs:

  • GetSpawnLocationData(Entity entity) — get SpawnLocationData from the spawn location's prefab (via PrefabRef).
  • GetRouteConnectionData(Entity entity) — get RouteConnectionData from prefab.
  • GetTransportLineData(Entity owner, out TransportLine transportLine) — if owner has a TransportLine component, returns its TransportLineData from prefab and outputs the TransportLine component value.
  • GetTransportLinePathfindData(TransportLineData) and GetNetLaneTransportPathfindData(Entity lane) — obtain PathfindTransportData from prefab pathfind prefabs for transport lines / net lanes.
  • GetSpawnLocationPathSpecification(...) — constructs an appropriate PathSpecification for a spawn location connection based on connection type (Pedestrian, Road/Cargo/Parking, Track, Air). It uses NetLaneData/prefab pathfind components and lane/curve information to compute distances, lane crossing counts and to select car/pedestrian/connection/track specific pathfind data.

Notes about data and behavior: - The system heavily relies on PrefabRef and per-prefab Pathfind data (PathfindTransportData, PathfindPedestrianData, PathfindCarData, PathfindTrackData, PathfindConnectionData) to build PathSpecifications. - For transport-line segments (Game.Routes.Segment) the system uses the RouteWaypoint buffer of the owning TransportLine entity to determine the next waypoint and builds transport-line-specific specifications using PathUtils.GetTransportLineSpecification. - The jobs are Burst-compiled for performance and operate on NativeList and ComponentLookups for random access. - The system uses Allocator.Persistent when allocating CreateAction / UpdateAction / DeleteAction objects that are enqueued; PathfindQueueSystem consumes them asynchronously.


Usage Example

// This is essentially what RoutesModifiedSystem does in OnCreate.
[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Get the queue system that will process the path actions:
    m_PathfindQueueSystem = base.World.GetOrCreateSystemManaged<PathfindQueueSystem>();

    // Create entity queries to detect created/updated/deleted/all sub-elements
    m_CreatedSubElementQuery = GetEntityQuery(new EntityQueryDesc {
        All = new ComponentType[] { ComponentType.ReadOnly<Created>() },
        Any = new ComponentType[] {
            ComponentType.ReadOnly<AccessLane>(),
            ComponentType.ReadOnly<RouteLane>(),
            ComponentType.ReadOnly<Game.Routes.Segment>(),
            ComponentType.ReadOnly<Game.Objects.SpawnLocation>()
        },
        None = new ComponentType[] {
            ComponentType.ReadOnly<Game.Routes.MailBox>(),
            ComponentType.ReadOnly<LivePath>(),
            ComponentType.ReadOnly<Temp>()
        }
    });

    // Similarly initialize m_UpdatedSubElementQuery, m_DeletedSubElementQuery and m_AllSubElementQuery
}

If you need documentation for any specific nested job, helper method or the data structures used in CreateActionData/UpdateActionData/DeleteActionData/PathSpecification, tell me which item and I will expand the documentation with field-by-field descriptions and examples.