Skip to content

Game.Net.LaneConnectionSystem

Assembly: Assembly-CSharp
Namespace: Game.Net

Type: class

Base: GameSystemBase

Summary:
LaneConnectionSystem is an ECS system responsible for discovering and maintaining lane-to-lane connections used by pathfinding and parking logic. It reacts to updated lanes, updated area lots/spaces and uses spatial search trees to find nearby lanes or connections. The system runs a set of Burst-compiled jobs to: - Find lanes that intersect updated area bounds (FindUpdatedLanesJob) - Enumerate lanes that were explicitly updated by components or spawn locations (CheckUpdatedLanesJob) - Merge and deduplicate updated lane lists (ListUpdatedLanesJob) - For each updated lane, search the world (areas and subnets) for the best lane connections and write or remove LaneConnection components (FindLaneConnectionJob)

The system integrates with SearchSystem and Game.Areas.SearchSystem for spatial queries and uses a ModificationBarrier5 to issue structural changes (EntityCommandBuffer) safely.


Fields

  • private ModificationBarrier5 m_ModificationBarrier
    Used to create a command buffer (EntityCommandBuffer.ParallelWriter) for safely adding/removing components (e.g., LaneConnection, PathfindUpdated) as a producer of structural changes.

  • private SearchSystem m_NetSearchSystem
    Reference to the network (net) spatial search system used to query net elements (subnets, lanes) with bounding boxes.

  • private Game.Areas.SearchSystem m_AreaSearchSystem
    Reference to the area search system used to query navigation/terrain areas (triangles, nodes) when finding area-based connections and pedestrian links.

  • private Game.Areas.UpdateCollectSystem m_AreaUpdateCollectSystem
    Reference to the area update collector that provides updated lot/space bounds lists (used to find lanes overlapping changed lots/spaces).

  • private EntityQuery m_UpdatedQuery
    An EntityQuery used to find entities that have Updated + SubLane and optionally Edge/Node/Object (and not Temp). Used to detect explicit lane updates.

  • private TypeHandle __TypeHandle
    Holds precomputed ComponentLookup / BufferLookup / ComponentTypeHandle values used by the jobs. Assigned in OnCreateForCompiler to speed access inside jobs.


Properties

  • This system exposes no public properties.

Constructors

  • public LaneConnectionSystem()
    Default constructor. The system is created/registered by the World; setup of referenced systems and queries is performed in OnCreate.

Methods

  • protected override void OnCreate()
    Initializes system references:
  • Creates/gets ModificationBarrier5, SearchSystem, Game.Areas.SearchSystem and Game.Areas.UpdateCollectSystem.
  • Creates the m_UpdatedQuery (entities with Updated + SubLane, any of Edge/Node/Object, and not Temp).
  • Prepares the system for scheduling the Burst jobs used in OnUpdate.

  • protected override void OnUpdate()
    Main runtime logic. When there are updated lanes or area lots/spaces updated it:

  • Allocates NativeQueue/NativeList containers for collecting updated sublane entities.
  • Schedules FindUpdatedLanesJob for updated lot bounds and/or updated space bounds (reads net search tree and curve/sub-lane data).
  • Schedules CheckUpdatedLanesJob to gather entities from updated query (spawn locations and sublane buffers).
  • Schedules ListUpdatedLanesJob to merge and deduplicate the collected queues into a NativeList.
  • Schedules FindLaneConnectionJob (parallel for deferred) over the merged list to compute LaneConnection results per entity:
    • For parking lanes: FindParkingConnection (searches subnets and areas to connect parking to pedestrian/road lanes; handles parking inversion and secondary start)
    • For road/pedestrian lanes: FindAreaConnection (searches area search tree for nearby connection lanes)
  • Uses ModificationBarrier5 command buffer to add/remove/update LaneConnection components and mark PathfindUpdated where necessary.
  • Registers job dependencies with the SearchSystems and with the ModificationBarrier (AddJobHandleForProducer).

  • protected override void OnCreateForCompiler()
    Helper called by compiler/engine-time to assign queries and initialize __TypeHandle lookups (calls __AssignQueries and __TypeHandle.__AssignHandles).

  • private void __AssignQueries(ref SystemState state)
    Internal helper (compiler-generated) that sets up any entity queries required by the system. In this decompiled form it constructs (and disposes) an EntityQueryBuilder (the real queries are built in OnCreate).

Nested jobs and responsibilities (Burst-compiled): - FindUpdatedLanesJob (IJobParallelForDefer)
- Uses a NativeQuadTree iterator to find net entities whose sublane curves intersect provided bounds list. Enqueues found entities to a result queue (parallel).

  • CheckUpdatedLanesJob (IJob)
  • Iterates updated archetype chunks (from m_UpdatedQuery) and enqueues sublane entities found in SubLane buffers.
  • Traverses Owner chains for entities to also enqueue spawn locations of type ParkingLane.
  • Uses a NativeHashSet to avoid duplicate owner handling.

  • ListUpdatedLanesJob (IJob)

  • Merges up to three NativeQueues into a NativeList, sorts by Entity.Index, and removes duplicates (compacts the list).

  • FindLaneConnectionJob (IJobParallelForDefer)

  • For each entity in the provided list, computes the best LaneConnection by:
    • Skipping if entity is a slave or connection lane (they don't get LaneConnection).
    • Handling parking lanes: FindParkingConnection checks nearby pedestrian lanes and road lanes from subnets and area triangles, considers installed upgrades, sets secondary start for two-way roads and parking inversion flags.
    • Handling road/pedestrian lanes: FindAreaConnection runs an area search (via m_AreaSearchTree) and checks ConnectionLane components to find the nearest start/end lanes within a configured max distance.
  • Adds/removes/updates LaneConnection components using the provided EntityCommandBuffer.ParallelWriter and marks PathfindUpdated when connections change.

Notes on component lookups used by jobs: - Curves, SubLane buffers, Owner data, ConnectionLane, Lane, SlaveLane, CarLane, ParkingLane, PrefabRef and many prefab data lookups (NetLaneData, CarLaneData, ParkingLaneData, NavigationAreaData) are read to decide matching lanes and distances. - Area triangle/node buffers and sub-area/sub-net buffers are used to search connectivity in the world.


Usage Example

// Typical usage within mod code: get the system and (for debugging) read a LaneConnection component from an entity
var world = World.DefaultGameObjectInjectionWorld; // or the game World instance
var laneConnectionSystem = world.GetExistingSystemManaged<Game.Net.LaneConnectionSystem>();
if (laneConnectionSystem != null)
{
    // LaneConnection components are created/updated by the system automatically when lanes or areas change.
    // To inspect, get an Entity and read the LaneConnection (using EntityManager in a safe context).
    var entityManager = world.EntityManager;
    Entity someLaneEntity = /* obtain a lane entity (e.g., from a buffer or saved reference) */;
    if (entityManager.HasComponent<LaneConnection>(someLaneEntity))
    {
        var connection = entityManager.GetComponentData<LaneConnection>(someLaneEntity);
        Debug.Log($"StartLane: {connection.m_StartLane}, EndLane: {connection.m_EndLane}");
    }
}

If you need a targeted example (e.g., how to trigger the system by marking a SubLane as Updated, or how to query FindLaneConnection results), tell me what workflow you want and I will provide a focused code sample.