Skip to content

Game.Vehicles.CarCurrentLane

Assembly: Game
Namespace: Game.Vehicles

Type: public struct CarCurrentLane : IComponentData, IQueryTypeParameter, ISerializable

Base: System.ValueType

Summary:
Represents the current lane state for a car within the ECS world. This struct is an IComponentData component attached to vehicle entities to track which lane the car occupies, any ongoing lane-change target/ progress, curve position on the lane, flags describing the lane, travel metrics (duration/distance) and the lane-relative position. It also implements custom binary serialization (ISerializable) used by the game's save/load system and network/entity serialization.


Fields

  • public Entity m_Lane
    The Entity representing the lane the car is currently using (target lane). May be Entity.Null when not set.

  • public Entity m_ChangeLane
    The Entity representing the lane the car is changing into (target lane during a lane change). Initialized to Entity.Null by constructors.

  • public float3 m_CurvePosition
    A float3 position on the lane curve (usually used for interpolation along a lane spline/curve).

  • public CarLaneFlags m_LaneFlags
    Bitflags describing lane-specific state (type, restrictions, or custom lane flags used by the vehicle/AI logic). Serialized as a uint.

  • public float m_ChangeProgress
    Progress of an ongoing lane change (0..1 typical), stored as a float.

  • public float m_Duration
    Time duration used for some lane-related timing (e.g., how long traversal has taken or expected). Stored as a float.

  • public float m_Distance
    Distance travelled (or remaining) on the current lane, stored as a float.

  • public float m_LanePosition
    Per-lane position value. Note: this field is conditionally deserialized — it is only read when the reader context version is >= Version.lanePosition. This allows backward compatibility with older save/serialization versions.

Properties

  • None (no public C# properties are declared on this struct).

Constructors

  • public CarCurrentLane(ParkedCar parkedCar, CarLaneFlags flags)
    Initializes a CarCurrentLane from a ParkedCar instance. Sets:
  • m_Lane = parkedCar.m_Lane
  • m_CurvePosition = parkedCar.m_CurvePosition
  • m_LaneFlags = flags
  • m_ChangeLane = Entity.Null
  • numeric fields (m_ChangeProgress, m_Duration, m_Distance, m_LanePosition) = 0f

  • public CarCurrentLane(PathElement pathElement, CarLaneFlags flags)
    Initializes a CarCurrentLane from a PathElement. Sets:

  • m_Lane = pathElement.m_Target
  • m_CurvePosition = pathElement.m_TargetDelta.xxx (extracts same value into a float3)
  • m_LaneFlags = flags
  • m_ChangeLane = Entity.Null
  • numeric fields (m_ChangeProgress, m_Duration, m_Distance, m_LanePosition) = 0f

(Additionally the default struct constructor is available, which will leave fields at their default values.)

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes all fields to the provided writer in the following order:
  • m_Lane (Entity)
  • m_ChangeLane (Entity)
  • m_CurvePosition (float3)
  • m_LaneFlags (written as uint)
  • m_ChangeProgress (float)
  • m_Duration (float)
  • m_Distance (float)
  • m_LanePosition (float)

This method ensures lane flags are stored as an unsigned integer and all numeric values are written in a stable order for deserialization.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads fields back from a reader. The method:
  • Reads m_Lane, m_ChangeLane, m_CurvePosition
  • Reads an unsigned int into a local value representing m_LaneFlags
  • Reads m_ChangeProgress, m_Duration, m_Distance
  • Conditionally reads m_LanePosition only if reader.context.version >= Version.lanePosition
  • Finally casts the read uint into CarLaneFlags and assigns to m_LaneFlags

This conditional read of m_LanePosition provides backward compatibility with older versions that did not include that field.

Usage Example

// Create from a ParkedCar:
ParkedCar parked = /* obtained from game state */;
var laneComponent = new CarCurrentLane(parked, CarLaneFlags.None);

// Or create from a PathElement:
PathElement pathElem = /* obtained from pathfinding */;
var laneFromPath = new CarCurrentLane(pathElem, CarLaneFlags.HasBusStop);

// Add to an entity (EntityManager usage example):
Entity vehicleEntity = /* vehicle entity */;
var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
entityManager.AddComponentData(vehicleEntity, laneComponent);

// Serialization is handled by the game's IWriter/IReader pipeline — example usage:
writer.Write(laneComponent); // assuming writer supports writing component structs

Notes: - Because this is an IComponentData, the struct is intended to be attached to vehicle entities in the DOTS ECS world and used/updated by systems that handle vehicle movement, lane changes, and pathfollowing. - Be mindful of the serialization version check for m_LanePosition when interacting with saved data or custom serialization logic.