Skip to content

Game.Vehicles.CarTrailerLane

Assembly: Assembly-CSharp
Namespace: Game.Vehicles

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents a trailer-related lane state for vehicles using the Unity ECS (Entity Component System). This struct stores references to the current lane and the next lane, positional data on the lane curve, and timing/distance information. It implements serialization (Serialize/Deserialize) so the state can be saved/loaded, and is intended to be used as a component on entities that need to track trailer lane information (e.g., when a vehicle with a trailer occupies or transitions lanes).


Fields

  • public Entity m_Lane
    Holds the Entity reference for the current lane the trailer is associated with.

  • public Entity m_NextLane
    Holds the Entity reference for the next lane the trailer will go to (Entity.Null when unknown/not set).

  • public float2 m_CurvePosition
    Stores a float2 representing the position along the lane curve (typically used to position the trailer relative to the lane spline).

  • public float2 m_NextPosition
    Stores a float2 for the next position on the lane curve (initialized to zero in the provided constructors).

  • public float m_Duration
    Float holding a duration/time value related to the lane state (initialized to 0 in constructors). Often used to track time spent or remaining for a transition.

  • public float m_Distance
    Float representing a distance metric along the lane (initialized to 0 in constructors).

Properties

  • (none)
    This struct does not declare any C# properties; it exposes its data via public fields and implements serialization methods.

Constructors

  • public CarTrailerLane(ParkedCar parkedCar)
    Initializes a CarTrailerLane from a ParkedCar instance:
  • m_Lane is set from parkedCar.m_Lane
  • m_NextLane = Entity.Null
  • m_CurvePosition = parkedCar.m_CurvePosition
  • m_NextPosition = (0,0)
  • m_Duration = 0
  • m_Distance = 0

  • public CarTrailerLane(CarCurrentLane currentLane)
    Initializes a CarTrailerLane from a CarCurrentLane instance:

  • m_Lane is set from currentLane.m_Lane
  • m_NextLane = Entity.Null
  • m_CurvePosition = currentLane.m_CurvePosition.xy
  • m_NextPosition = (0,0)
  • m_Duration = 0
  • m_Distance = 0

These constructors provide convenient ways to seed trailer lane state from existing parked or current lane components.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the fields to the provided writer in the following order: m_Lane, m_NextLane, m_CurvePosition, m_NextPosition, m_Duration, m_Distance. Use the matching Colossal.Serialization writer implementation when saving component state.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads fields from the provided reader into this instance in the same order they are written by Serialize. The caller must ensure reader/writer pair and field order compatibility to avoid corrupt data.

Notes: - The generic constraints require an IWriter/IReader implementation from the game's serialization framework (Colossal.Serialization). - The order of Read/Write operations must match exactly between Serialize and Deserialize for save/load compatibility.

Usage Example

// Create from a parked car component
ParkedCar parkedCar = /* obtain parked car component */;
CarTrailerLane trailerLane = new CarTrailerLane(parkedCar);

// Modify fields if needed
trailerLane.m_NextLane = nextLaneEntity;
trailerLane.m_Distance = 12.5f;

// Serialize (writer must be a game-provided IWriter implementation)
writer.Write(trailerLane.m_Lane);
trailerLane.Serialize(writer);

// Deserialize (reader must be the matching IReader)
CarTrailerLane loaded = default;
loaded.Deserialize(reader);

// Attach to an entity as a component (ECS)
entityManager.AddComponentData(someEntity, loaded);

Additional tips for modders: - Because this is an IComponentData, prefer using EntityManager or Systems to add/remove/query this component in ECS systems. - Always use the game's provided IWriter/IReader implementations for save/load; custom writers/readers must maintain the same field order and types. - The float2 fields are from Unity.Mathematics; assigning 0f initializes them to (0,0).