Game.Pathfind.LanesModifiedSystem
Assembly: Assembly-CSharp
Namespace: Game.Pathfind
Type: class
Base: GameSystemBase
Summary:
LanesModifiedSystem monitors lane entities (car lanes, track lanes, parking lanes, pedestrian lanes, connection lanes) in the ECS world and converts entity changes into pathfinding queue actions. It detects created, updated and deleted Lane entities using EntityQueries and schedules Burst-compiled jobs (AddPathEdgeJob, UpdatePathEdgeJob, RemovePathEdgeJob) that produce CreateActionData / UpdateActionData / DeleteActionData arrays. These arrays are wrapped in CreateAction / UpdateAction / DeleteAction objects and enqueued into the PathfindQueueSystem for the pathfinder to process. The system also supports a one-time full scan after the game is loaded (m_Loaded).
Fields
-
private PathfindQueueSystem m_PathfindQueueSystem
Contains a reference to the PathfindQueueSystem used to enqueue generated create/update/delete actions for the pathfinding subsystem. -
private EntityQuery m_CreatedLanesQuery
EntityQuery matching newly created Lane entities (Created + Lane) for lane types the system cares about. Used to gather chunks for AddPathEdgeJob. -
private EntityQuery m_UpdatedLanesQuery
EntityQuery matching updated Lane entities (Updated + Lane) for lane types the system cares about. Used to gather chunks for UpdatePathEdgeJob. -
private EntityQuery m_DeletedLanesQuery
EntityQuery matching deleted Lane entities (Deleted + Lane) for lane types the system cares about. Used to gather chunks for RemovePathEdgeJob. -
private EntityQuery m_AllLanesQuery
EntityQuery matching all existing Lane entities (used by the one-time full scan after loading to create path edges for all lanes). -
private bool m_Loaded
Flag set by OnGameLoaded to indicate a game load event; causes a full scan of lanes on the next update. GetLoaded() consumes the flag. -
private TypeHandle __TypeHandle
Holds the ComponentLookup / ComponentTypeHandle / EntityTypeHandle instances used to build jobs safely and efficiently. __TypeHandle.__AssignHandles(ref SystemState) initializes these handles.
Properties
- None (this system exposes no public properties)
Constructors
public LanesModifiedSystem()
Default constructor (marked with [Preserve] on class methods). Initialization of queries and handles is done in OnCreate / OnCreateForCompiler rather than constructor.
Methods
-
protected override void OnCreate()
Creates the EntityQueries used by the system and initializes a reference to the PathfindQueueSystem. Queries are constructed to capture Created/Updated/Deleted lane entities for different lane types (car, track, parking, pedestrian, connection) while excluding Temp / SlaveLane components as needed. -
protected override void OnGameLoaded(Context serializationContext)
Called when the game serialization/loading is finished. Sets m_Loaded to true so the next OnUpdate performs a full scan (m_AllLanesQuery) to enqueue path data for all lanes. -
private bool GetLoaded()
Returns true once when a game load occurred (consumes m_Loaded). OnUpdate uses this to decide between a full scan and incremental processing. -
protected override void OnUpdate()
Main system execution. Determines counts for created / updated / deleted lanes and, if there is work, schedules Burst jobs: - For creations: constructs a CreateAction (backed by NativeArray
), builds a NativeList asynchronously from the created query, schedules AddPathEdgeJob to fill the create data, disposes chunk list, and enqueues the action into PathfindQueueSystem. - For updates: analogous flow using UpdatePathEdgeJob and an UpdateAction.
-
For deletions: analogous flow using RemovePathEdgeJob and a DeleteAction. JobHandles are combined with base.Dependency and the system's Dependency is updated at the end.
-
private void __AssignQueries(ref SystemState state)
Compiler helper invoked from OnCreateForCompiler. Currently the implementation in this class just uses a temporary EntityQueryBuilder (no-op here) but exists to satisfy codegen / compiler patterns for generated systems. -
protected override void OnCreateForCompiler()
Sets up compiler-time state and assigns component/handle lookups by calling __AssignQueries and __TypeHandle.__AssignHandles. -
AddPathEdgeJob (private nested Burst-compiled struct implementing IJob)
Iterates selected archetype chunks, reads Lane, Curve, PrefabRef and lane-type components (CarLane, TrackLane, ParkingLane, PedestrianLane, ConnectionLane, etc.), looks up prefab pathfind data (PathfindCarData/TrackData/TransportData/ConnectionData/PedestrianData) and net lane/prefab lane data, optionally checks lane connections (to replace start/end nodes with linked lanes' middle nodes when LaneConnection exists). It computes Path specifications using PathUtils (GetCarDriveSpecification, GetTaxiDriveSpecification, GetTrackDriveSpecification, GetParkingSpaceSpecification, GetSpecification, GetSecondarySpecification, GetLocationSpecification, etc.) and writes CreateActionData entries to the provided NativeArray. Also accounts for Owner density component to adjust pathfinding parameters (density scaling). -
UpdatePathEdgeJob (private nested Burst-compiled struct implementing IJob)
Very similar to AddPathEdgeJob but writes UpdateActionData entries for updated lanes. It performs the same per-lane logic to produce up-to-date path specifications and locations, using the same PathUtils helpers and lane-type-specific behavior. -
RemovePathEdgeJob (private nested Burst-compiled struct implementing IJob)
Simpler job that iterates selected entity chunks and produces DeleteActionData entries containing the Entity owner for each deleted lane to remove path edges. -
TypeHandle.__AssignHandles(ref SystemState) (nested struct method)
Initializes ComponentLookupand ComponentTypeHandle / EntityTypeHandle fields used by jobs via the SystemState. This ties into Unity's safety and job system so the jobs can access component data in parallel or read-only contexts.
Notes about jobs and behavior:
- All lane-processing jobs are marked with [BurstCompile] to run efficiently.
- Jobs use ComponentLookup
Usage Example
// Ensure the system exists (typical usage from other systems/mod code)
var lanesSystem = World.GetOrCreateSystemManaged<Game.Pathfind.LanesModifiedSystem>();
// You normally don't call its internals — it will run automatically each frame and enqueue
// pathfinding actions when lanes are created/updated/deleted. If you need to force a full
// rebuild after a custom load step, you can simulate OnGameLoaded or manipulate the state
// that causes the system to pick up changes (not recommended unless you know internal invariants).
Additional tips for modders: - If you need to hook into the same pipeline, monitor or modify PathfindQueueSystem contents rather than changing LanesModifiedSystem directly; PathfindQueueSystem is the consumer of created/updated/deleted actions. - When creating custom lane prefabs or extending lane-related prefab data, ensure you provide compatible Pathfind*Data / NetLaneData so LanesModifiedSystem's PathUtils calls return correct specifications. - Be mindful of job safety: modifying ComponentTypeHandles or ComponentLookup state incorrectly can introduce race conditions. Prefer using high-level ECS APIs or creating separate systems that run at appropriate moments if you need custom behavior.