Skip to content

Game.Vehicles.FixParkingLocationSystem

Assembly: Assembly-CSharp (game runtime)
Namespace: Game.Vehicles

Type: public class

Base: GameSystemBase

Summary:
FixParkingLocationSystem is a world/system-level job-driven system that ensures parked vehicles (cars and trains) remain assigned to valid parking locations after network or object updates (lanes, spawn locations, buildings, deletions, etc.). It collects parked vehicles that need processing, searches for appropriate parking lanes or spawn locations, updates vehicle transforms and parked-data, manages unspawned/spawn states, updates lane objects and search trees, and issues ECS commands (via a modification barrier) for required entity component changes. The system uses two Burst-compiled jobs: CollectParkedCarsJob (gather vehicles to fix) and FixParkingLocationJob (find/assign/validate parking spaces and perform updates).


Fields

  • private ModificationBarrier5 m_ModificationBarrier
    Holds the modification barrier system used to produce EntityCommandBuffer operations safely from jobs. Used to add/remove components (e.g., Unspawned, Updated, PathfindUpdated, FixParkingLocation).

  • private Game.Objects.SearchSystem m_ObjectSearchSystem
    Reference to the objects search system used to read/write object search trees (static and moving object search trees). Used to query nearby static/moving objects and to update the moving search tree.

  • private Game.Net.SearchSystem m_NetSearchSystem
    Reference to the network search system used to read lane search trees (for parking lane lookup).

  • private EntityQuery m_FixQuery
    EntityQuery used to drive/require system updates. Matches network/objects updates and filters relevant component combinations so the system runs only when needed.

  • private TypeHandle __TypeHandle
    Holds the generated Component/Buffer/Entity type handles and ComponentLookup/BufferLookup handles used by the job structs (populated by __AssignHandles). Internal to the generated job binding.

Properties

  • None
    This system exposes no public properties.

Constructors

  • public FixParkingLocationSystem()
    Default public constructor. The system is normally created by the ECS world; it initializes internal fields in OnCreate (GetOrCreateSystemManaged calls, query creation, and RequireForUpdate).

Methods

  • protected override void OnCreate()
    Initializes the system: obtains references to ModificationBarrier5, Object and Net search systems, constructs the m_FixQuery (queries that trigger the system), and calls RequireForUpdate to ensure it runs only when the query matches.

  • protected override void OnUpdate()
    Main update method that:

  • Allocates a NativeQueue to collect vehicles to process.
  • Schedules CollectParkedCarsJob (IJobChunk) to gather parked vehicles or lane-objects that need fixing into the queue.
  • Schedules FixParkingLocationJob (IJob) to dequeue and process vehicles: find valid parking lanes/spawn locations, assign parked data, update transforms, add/remove Unspawned/Updated/BatchesUpdated components, update lane objects, update moving/static search trees, and enqueue PathfindUpdated for lanes that changed.
  • Hooks job dependencies into the search systems and modification barrier so read/write locks are respected.
  • Cleans up temporary structures once jobs complete.

  • protected override void OnCreateForCompiler()
    Internal-generated method used when compiling the system; assigns handles and prepares query bindings for the compiler-generated accessors. (Calls __AssignQueries and TypeHandle assignment.)

  • private void __AssignQueries(ref SystemState state)
    Generated helper: currently used to initialize entity query builders during compiler setup. Internal use.

  • (Nested) CollectParkedCarsJob : IJobChunk
    Burst-compiled chunk job that iterates archetype chunks and collects Entities that should be processed by the system into a NativeQueue (ParallelWriter). Responsibilities:

  • If a chunk contains FixParkingLocation, enqueue the entity directly.
  • If chunk has LaneObject buffers, remove parked vehicles from the buffers and enqueue them.
  • If chunk contains ConnectionLane with Parking flag, search the moving-object search tree for parked cars on that lane and enqueue them.
  • If chunk contains SpawnLocation (air/track), gather parked vehicles near spawn locations or parked trains connected to track lanes and enqueue them.
  • Uses ComponentTypeHandles, BufferTypeHandle, ComponentLookup, BufferLookup, and NativeQuadTree for spatial searches.

  • (Nested) FixParkingLocationJob : IJob
    Burst-compiled job that processes the queue of vehicles and tries to find and set valid parking locations. High-level responsibilities:

  • Maintain a map tracking which vehicles were unspawned at start to avoid duplicate work.
  • For each vehicle in the queue: determine if it's a parked car or parked train, handle existing FixParkingLocation component removal, attempt to find garage spots when appropriate, handle lane/object updates, recalculate parked transforms, add/remove lane objects, update search trees, and set Unspawned/Updated/BatchesUpdated components as necessary.
  • When assigning to parking lanes, it can compute the parking curve position (componentData.m_CurvePosition) for parking slots or use spawn locations (air/track).
  • For trains, it can build spawn paths and update carriage positions across multiple vehicles.

Important helper methods inside FixParkingLocationJob: - UpdateTrainLocation(Entity entity, Entity parkingLocation, DynamicBuffer layout, ref NativeList laneBuffer)
Recalculates path/lane positions for a parked train's carriages and adds them back to lane lane-objects.

  • RemoveTrainFromLanes(DynamicBuffer layout) / AddTrainToLanes(DynamicBuffer layout)
    Remove / add train carriages from/to lane object buffers when relocating.

  • ValidateParkedTrain(DynamicBuffer layout) : bool
    Ensures all carriages of a parked train reference valid lanes in the current entity storage.

  • AddToSearchTree(Entity entity, Transform transform, ObjectGeometryData objectGeometryData)
    Computes object bounds and adds/updates the entity in the moving-object search tree.

  • UpdateParkedCar(Entity entity, Transform oldTransform, Transform transform, ParkedCar parkedCar)
    Update the vehicle Transform and parked-car data, mark Updated and propagate sub-object transforms.

  • UpdateSubObjects(Entity entity, Transform transform)
    Recursively updates transforms of attached sub-objects (Relative components) and marks them Updated.

  • UpdateParkedTrain(Entity entity, Transform oldTransform, Transform transform, ParkedTrain parkedTrain)
    Same as UpdateParkedCar but for train carriages (updates ParkedTrain data and transforms).

  • RemoveCarKeeper(Entity entity)
    If a personal car had a CarKeeper linking it to a citizen, clear that link when the parked-car is removed.

  • FindGarageSpot(ref Random random, Entity vehicle, Entity lane, ref Transform transform) : bool
    When a vehicle belongs to a building owner with ActivityLocation (garage spots), this helper collects candidate garage spots, queries the moving-object search tree to mark occupied spots, and picks an available spot (with some randomness). If selected, transforms the vehicle to the garage spot.

  • Several spatial iterators and binary-search based helpers exist inside the job (OccupySpotsIterator, LaneIterator, etc.) to find lanes/spawn locations and detect occupied spots efficiently.

Usage Example

// Mark a vehicle entity so FixParkingLocationSystem will process it on the next update.
// (Assumes you have an EntityManager and a vehicle entity to operate on.)
var fixComponent = new FixParkingLocation {
    // m_ChangeLane / m_ResetLocation etc. are fields present on FixParkingLocation component in-game.
    // Set these fields as appropriate; here we clear m_ResetLocation to let the system compute a new parking spot.
    m_ChangeLane = Entity.Null,
    m_ResetLocation = Entity.Null
};
entityManager.AddComponentData(vehicleEntity, fixComponent);

// Alternatively, the system runs automatically when relevant lanes/spawn locations are Updated/Deleted.
// You can also obtain the running system instance (read-only) like this:
var world = Unity.Entities.World.DefaultGameObjectInjectionWorld;
var fixSystem = world.GetExistingSystemManaged<Game.Vehicles.FixParkingLocationSystem>();
// Note: systems run in the ECS scheduler; you generally don't call them directly.

If you want more details (component fields used by this system, the FixParkingLocation component shape, or how to trigger specific behaviors like forcing a vehicle to become Unspawned/Spawned), tell me which part you'd like expanded (e.g., parked car data flow, lane-object buffers, or how trains are handled).