Skip to content

Game.Net.FixLaneObjectsSystem

Assembly: Game (assembly name may vary)
Namespace: Game.Net

Type: class

Base: GameSystemBase

Summary:
FixLaneObjectsSystem is an ECS system responsible for maintaining and repairing "lane object" references for moving and parked entities in the game (cars, car trailers, humans, animals, trains, watercraft, aircraft). It collects lane objects from entity buffers, enqueues those that need updating, and then runs a worker job that re-resolves current lanes using multiple spatial search trees (net, area, static objects, moving objects). The system uses burst-compiled jobs (CollectLaneObjectsJob and FixLaneObjectsJob), a NativeQueue to coordinate work between jobs, and a LaneObjectUpdater to apply buffer modifications via a ModificationBarrier. It ensures entities' CurrentLane/TrailerLane/Etc. components are updated and any associated LaneObject buffers are kept consistent.


Fields

  • private ModificationBarrier5 m_ModificationBarrier
    Used to apply structural/buffer modifications produced by the lane object updater; ensures safe producer/consumer scheduling with the entity manager.

  • private SearchSystem m_NetSearchSystem
    Read-only access to the net (roads/rails/etc.) spatial search tree used to find lanes.

  • private Game.Areas.SearchSystem m_AreaSearchSystem
    Read-only access to area search data (used for area-aware lane queries, e.g., water/animals/humans).

  • private Game.Objects.SearchSystem m_ObjectSearchSystem
    Read-only access to object search trees (static and moving objects) used during lane searches.

  • private EntityQuery m_LaneQuery
    The entity query used by the CollectLaneObjectsJob. Targets entities that contain LaneObject and Lane components and excludes temporary/parking lanes; requires Deleted or Updated tags for iteration.

  • private LaneObjectUpdater m_LaneObjectUpdater
    Helper that accumulates LaneObject buffer changes and applies them via the modification barrier. It is used to batch and apply updates created by the jobs.

  • private TypeHandle __TypeHandle
    Generated container that stores ComponentLookup/BufferLookup/TypeHandle instances used by the jobs. It has an __AssignHandles method to initialize lookups from a SystemState.


Properties

  • None (this system does not expose public properties)

{{ The system relies entirely on private/internal lookups and job-local data; all updates are applied via the LaneObjectUpdater and modification barrier rather than exposed properties. }}

Constructors

  • public FixLaneObjectsSystem()
    Default constructor. The system performs initialization in OnCreate (obtaining required systems, preparing the entity query and LaneObjectUpdater).

{{ The constructor itself has no custom initialization logic beyond what the base GameSystemBase constructor does; OnCreate is used for setup. }}

Methods

  • protected override void OnCreate() : System.Void
    Initializes the system: gets/creates required systems (ModificationBarrier5, SearchSystem, Area search, Object search), constructs the EntityQuery (m_LaneQuery) that selects entities with LaneObject and Lane components, creates the LaneObjectUpdater and calls RequireForUpdate(m_LaneQuery) so the system only runs when relevant entities exist.

{{ OnCreate mirrors typical ECS system setup: build queries, cache references to other systems and initialize helpers. The query excludes Temp and ParkingLane and requires Deleted or Updated tags in Any, matching the intended update cases. }}

  • protected override void OnUpdate() : System.Void
    Main runtime logic. It:
  • Allocates a NativeQueue to collect lane-objects that need fixing.
  • Constructs and schedules a CollectLaneObjectsJob (IJobChunk, Burst compiled) that iterates over chunk buffers of LaneObject, prunes/removes invalid entries (parked cars/trains are preserved), and enqueues relevant lane object entities that need lane resolution.
  • Prepares and schedules a FixLaneObjectsJob (IJob, Burst compiled) that:
    • Dequeues entities from the queue (deduplicating with a NativeParallelHashSet).
    • For each entity, based on its type component (CarCurrentLane, CarTrailerLane, HumanCurrentLane, AnimalCurrentLane, TrainCurrentLane, WatercraftCurrentLane, AircraftCurrentLane), executes the appropriate UpdateX(...) routine to find the best current lane(s) using various FindLaneIterator implementations and spatial search trees.
    • Uses cached lane data to preserve some fields when the lane identity does not change, or mark lane flags as Obsolete when lanes change.
    • Uses various CurrentLaneCache / TrailerLaneCache helpers to detect changes and enqueue LaneObject buffer changes into LaneObjectCommandBuffer.
  • Adds the job handles to registered search systems (readers), disposes the NativeQueue via scheduled dispose, informs the modification barrier of the producer job handle, and applies the LaneObjectUpdater changes, chaining returned JobHandle into base.Dependency.

{{ OnUpdate orchestrates the producer/consumer flow between the chunk job that collects lane objects and the single-job worker that does lane resolution. It also coordinates read access to spatial search trees and ensures proper scheduling and disposal of temporary allocations. }}

  • protected override void OnCreateForCompiler() : System.Void
    Compiler helper called for AOT/IL2CPP compatibility. It assigns generated query handles and initializes the __TypeHandle lookups by calling __AssignHandles on the TypeHandle using the SystemState.

{{ This method is used in generated code paths to ensure lookups are set up for Burst/AOT contexts. }}

  • private void __AssignQueries(ref SystemState state) : System.Void
    Internal helper used during compiler-time initialization to (currently) build/validate queries. In the generated file it creates and disposes an EntityQueryBuilder; its real query setup happens in OnCreate.

{{ This is a generated boilerplate helper used by the game's source generation tooling. }}

  • private struct CollectLaneObjectsJob : IJobChunk (nested)
    Burst-compiled IJobChunk that:
  • Has ComponentLookup fields for parked cars/trains and current-lane components, and a BufferTypeHandle.
  • Iterates over chunks whose entities include a LaneObject buffer; for each LaneObject element it:
    • Keeps parked car/train lane objects intact.
    • Keeps lane objects that have a CurrentLane-like component (Car/Human/Animal/Train/Watercraft/Aircraft), and enqueues the underlying lane object Entity to the NativeQueue (via ParallelWriter) for later processing.
    • Removes any other lane object entries from the buffer (pruning invalid references).
  • This job builds the work list for FixLaneObjectsJob.

{{ CollectLaneObjectsJob is scheduled in parallel over the query so it uses a ParallelWriter for the lane-object queue. Its work is purely read-only for most component lookups and writes only to lane object buffers and the queue. }}

  • private struct FixLaneObjectsJob : IJob (nested)
    Burst-compiled IJob that consumes the queue of lane object Entities and performs full lane resolution for each entity type. Key points:
  • Holds many ComponentLookup / BufferLookup references (transform, moving, navigation, lane data, prefab data, etc.) and the spatial search trees (m_NetSearchTree, m_AreaSearchTree, m_StaticObjectSearchTree, m_MovingObjectSearchTree).
  • Uses a NativeParallelHashSet to deduplicate items from the queue.
  • Dispatches to specialized UpdateX(Entity, ...) methods:
    • UpdateCar / UpdateCarTrailer: handle cars and trailers, consider OutOfControl, compute pivots for trains/trailers, locate lanes and blocked lanes, and preserve certain lane-change fields when lane identity remains the same.
    • UpdateHuman / UpdateAnimal: use area/static/moving search trees plus hangaround locations and pedestrian lane data.
    • UpdateTrain: handles front/rear lane resolution for trains, uses vehicle-specific pivot calculations and train-specific lane caches.
    • UpdateWatercraft / UpdateAircraft: use area search (watercraft) and special car type flags (helicopter vs airplane) and their respective navigation helpers.
  • Each UpdateX uses a CurrentLaneCache or similar helper to call CheckChanges which writes LaneObject buffer updates to the supplied LaneObjectCommandBuffer.
  • After processing, disposes temporary lists and sets updated CurrentLane components back to their entities via component lookups.

{{ FixLaneObjectsJob encapsulates most of the lane-resolution logic and relies on many helper types (NavigationHelpers, CurrentLaneCache, FindLaneIterator) from the game's navigation/physics code. It is scheduled after CollectLaneObjectsJob completes. }}

  • private struct TypeHandle (nested)
    Generated struct containing all ComponentLookup, BufferLookup and BufferTypeHandle fields needed by the jobs. It exposes __AssignHandles(ref SystemState state) which initializes all lookups from the provided SystemState.

{{ TypeHandle is generated to avoid repeatedly recreating lookups per update; it centralizes handle initialization for the system's jobs. }}

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Typical setup performed by FixLaneObjectsSystem:
    m_ModificationBarrier = World.GetOrCreateSystemManaged<ModificationBarrier5>();
    m_NetSearchSystem = World.GetOrCreateSystemManaged<SearchSystem>();
    m_AreaSearchSystem = World.GetOrCreateSystemManaged<Game.Areas.SearchSystem>();
    m_ObjectSearchSystem = World.GetOrCreateSystemManaged<Game.Objects.SearchSystem>();

    // Build the query to find entities with LaneObject buffers to examine.
    m_LaneQuery = GetEntityQuery(new EntityQueryDesc {
        All = new ComponentType[] {
            ComponentType.ReadOnly<LaneObject>(),
            ComponentType.ReadOnly<Lane>()
        },
        Any = new ComponentType[] {
            ComponentType.ReadOnly<Deleted>(),
            ComponentType.ReadOnly<Updated>()
        },
        None = new ComponentType[] {
            ComponentType.ReadOnly<Temp>(),
            ComponentType.ReadOnly<ParkingLane>()
        }
    });

    m_LaneObjectUpdater = new LaneObjectUpdater(this);

    // Only run when there are matched entities.
    RequireForUpdate(m_LaneQuery);
}

{{ This example shows the main initialization pattern used by the system. At runtime OnUpdate schedules the CollectLaneObjectsJob and FixLaneObjectsJob to collect and resolve lanes for all relevant entities, and applies the lane-object buffer changes using LaneObjectUpdater and ModificationBarrier5. }}