Skip to content

Game.Pathfind.RouteDataSystem

Assembly: Game (Assembly-CSharp)
Namespace: Game.Pathfind

Type: class

Base: GameSystemBase

Summary:
RouteDataSystem is an ECS system that updates route-related component data for entities that expose route functionality: TransportStop, TakeoffLocation and SpawnLocation. It inspects each entity's Owner, PrefabRef and prefab data (RouteConnectionData, SpawnLocationData, BuildingData) and sets access restriction entity references and entry/exit flags accordingly. The heavy work is performed in a Burst-compiled IJobChunk (UpdateRouteDataJob) that runs in parallel for matching chunks. The system takes into account attachments and owner chains when resolving which building (if any) enforces access restrictions.


Fields

  • private Unity.Entities.EntityQuery m_UpdateQuery
    Contains the query used to find entities that need their route data updated (entities with Updated/PathfindUpdated together with any of TransportStop / TakeoffLocation / SpawnLocation and without Deleted/MailBox/Temp). The system calls RequireForUpdate with this query so it only runs when relevant entities exist.

  • private RouteDataSystem.TypeHandle __TypeHandle
    Struct that caches ComponentTypeHandle and ComponentLookup handles for all component types used by the job (Owner, PrefabRef, TransportStop, TakeoffLocation, SpawnLocation and various ComponentLookup instances for Attachment, Building, prefab data types). These handles are assigned in OnCreateForCompiler and used to build the job's input handles on each update.

Properties

  • None (the system does not expose public properties)

Constructors

  • public RouteDataSystem()
    Default constructor. The system relies on OnCreate / OnUpdate lifecycle methods to set up queries and schedule jobs.

Methods

  • [Preserve] protected override void OnCreate()
    Creates and configures the m_UpdateQuery used to select entities to process. It sets up two EntityQueryDesc variants (one using Updated, the other using PathfindUpdated) with Any = TransportStop, TakeoffLocation, SpawnLocation and excludes Deleted, MailBox and Temp. The method calls RequireForUpdate to ensure the system only runs when matching entities are present.

  • [Preserve] protected override void OnUpdate()
    Builds an UpdateRouteDataJob instance and schedules it in parallel via JobChunkExtensions.ScheduleParallel. The job receives ComponentTypeHandle and ComponentLookup instances from __TypeHandle via InternalCompilerInterface/GetComponentTypeHandle / GetComponentLookup wrappers and uses base.Dependency for job chaining.

  • private void __AssignQueries(ref SystemState state)
    Generated helper (called from OnCreateForCompiler) that currently contains a no-op EntityQueryBuilder usage. Present to satisfy compiler-generated requirements.

  • protected override void OnCreateForCompiler()
    Compiler helper that calls __AssignQueries and __TypeHandle.__AssignHandles to initialize cached handles for compiler scenarios.

Nested types and job methods (important internals):

  • private struct UpdateRouteDataJob : IJobChunk (BurstCompile)
  • Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    Iterates chunk arrays of TransportStop, TakeoffLocation and SpawnLocation (and Owner/PrefabRef where present) and:
    • Resets m_AccessRestriction and clears AllowEnter/AllowExit flags.
    • If an Owner/PrefabRef is present, uses prefab route/spawn data to compute restrict flags (via GetRestrictFlag) and resolves the access restriction entity with GetAccessRestriction.
    • Sets flags (StopFlags.AllowEnter, SpawnLocationFlags.AllowEnter/AllowExit, TakeoffLocationFlags.AllowEnter/AllowExit) based on the resolved allowEnter/allowExit booleans and, for takeoff locations, copies flags from associated SpawnLocation if present.
  • GetRestrictFlag(RouteConnectionType routeConnectionType, RoadTypes routeRoadType) : Game.Prefabs.BuildingFlags
    Maps route connection types and road-type masks to BuildingFlags that represent restrictions (e.g., RestrictedCar, RestrictedPedestrian, RestrictedTrack, combinations for Parking, etc.). Returns 0 when no restriction applies.
  • GetAccessRestriction(Owner owner, Game.Prefabs.BuildingFlags flag, bool isTakeOffLocation, out bool allowEnter, out bool allowExit) : Entity
    Resolves the top-level owner by walking owner.m_Owner chain, then follows Attachment.m_Attached if present to find an enforcing entity. If that entity is a Building, it checks the building's prefab BuildingData flags against the requested restriction flag and computes allowEnter / allowExit according to the logic in the job:

    • If building has the specific flag, allowEnter = !flag2 (flag2 is building has exact flag)
    • For car/pedestrian combinations and parking, allowExit is computed considering RestrictedParking and special takeoff-location rules (takeoff allows enter/exit for cars only when isTakeOffLocation is true).
    • Returns the enforcing entity or Entity.Null and sets allowEnter/allowExit to false when no restriction applies.
  • void IJobChunk.Execute(...)
    Explicit interface implementation that just forwards to the strongly-typed Execute method.

  • private struct TypeHandle

  • __AssignHandles(ref SystemState state)
    Assigns all ComponentTypeHandle and ComponentLookup fields from the provided SystemState (used in OnCreateForCompiler). These include read-only Owner and PrefabRef type handles, read/write handles for TransportStop/TakeoffLocation/SpawnLocation, and component lookups for Owner, Attachment, Building, PrefabRef, BuildingData, RouteConnectionData, SpawnLocationData.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Query selects entities that need route data updates (transport stops, takeoff locations, spawn locations)
    m_UpdateQuery = GetEntityQuery(new EntityQueryDesc
    {
        All = new ComponentType[1] { ComponentType.ReadOnly<Updated>() },
        Any = new ComponentType[3]
        {
            ComponentType.ReadOnly<Game.Routes.TransportStop>(),
            ComponentType.ReadOnly<Game.Routes.TakeoffLocation>(),
            ComponentType.ReadOnly<Game.Objects.SpawnLocation>()
        },
        None = new ComponentType[3]
        {
            ComponentType.ReadOnly<Deleted>(),
            ComponentType.ReadOnly<Game.Routes.MailBox>(),
            ComponentType.ReadOnly<Temp>()
        }
    },
    // second variant for PathfindUpdated-only updates (the system constructs both)
    new EntityQueryDesc
    {
        All = new ComponentType[1] { ComponentType.ReadOnly<PathfindUpdated>() },
        Any = new ComponentType[3]
        {
            ComponentType.ReadOnly<Game.Routes.TransportStop>(),
            ComponentType.ReadOnly<Game.Routes.TakeoffLocation>(),
            ComponentType.ReadOnly<Game.Objects.SpawnLocation>()
        },
        None = new ComponentType[4]
        {
            ComponentType.ReadOnly<Updated>(),
            ComponentType.ReadOnly<Deleted>(),
            ComponentType.ReadOnly<Game.Routes.MailBox>(),
            ComponentType.ReadOnly<Temp>()
        }
    });

    RequireForUpdate(m_UpdateQuery);
}

Additional notes: - The job is Burst-compiled for performance and is scheduled as a parallel chunk job; ensure thread-safety when adding or modifying related components in other systems. - The system expects certain prefab data components (RouteConnectionData, SpawnLocationData, BuildingData) to be available on referenced prefabs; if those are missing, lookups will return default values or may throw if misused—modders should avoid changing the expected prefab schemas.