Skip to content

Game.Vehicles.TrainNavigationLane

Assembly: Assembly-CSharp (typical for Cities: Skylines 2 game code)
Namespace: Game.Vehicles

Type: struct

Base: IBufferElementData, ISerializable

Summary:
Represents one navigation entry for a train lane used with Unity's ECS dynamic buffers. The struct stores a reference to the lane Entity, a 2D curve position (float2) along that lane, and lane-specific flags (TrainLaneFlags). It is marked with [InternalBufferCapacity(0)] (a dynamic buffer hint) and implements ISerializable to support Colossal's serialization system for saving/loading mod/game data.


Fields

  • public Entity m_Lane
    Represents the Entity that identifies the lane this navigation entry belongs to. Typically an ECS Entity corresponding to an in-game lane.

  • public float2 m_CurvePosition
    A 2D position (float2) along the lane's curve — used to place/track the train on the lane geometry.

  • public TrainLaneFlags m_Flags
    Bitmask flags describing properties of the lane (uses the TrainLaneFlags enum). Serialized as a uint.

Properties

  • None. This type exposes only public fields and no C# properties.

Constructors

  • public TrainNavigationLane()
    No explicit constructors are declared in the source; the default struct constructor applies and fields are default-initialized (Entity = default, float2 = (0,0), flags = default).

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the three fields in order to the provided writer: m_Lane (Entity), m_CurvePosition (float2), and m_Flags (written as a uint). Used by Colossal.Serialization.Entities to persist this buffer element.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the three fields back from the reader into the struct fields in the same order: lane, curvePosition, then reads a uint and casts it to TrainLaneFlags for m_Flags.

Usage Example

// Add a navigation entry to a train entity's buffer
Entity trainEntity = /* obtain train entity */;
Entity laneEntity = /* obtain lane entity */;

var buffer = EntityManager.GetBuffer<TrainNavigationLane>(trainEntity);
buffer.Add(new TrainNavigationLane {
    m_Lane = laneEntity,
    m_CurvePosition = new Unity.Mathematics.float2(0.5f, 0.0f),
    m_Flags = TrainLaneFlags.None
});

// Reading back
for (int i = 0; i < buffer.Length; i++)
{
    TrainNavigationLane nav = buffer[i];
    Entity lane = nav.m_Lane;
    Unity.Mathematics.float2 pos = nav.m_CurvePosition;
    TrainLaneFlags flags = nav.m_Flags;
    // use lane / pos / flags...
}

Notes: - The struct's ISerializable implementation integrates with the game's Colossal.Serialization.Entities system to allow buffers containing this element to be saved and restored. - The [InternalBufferCapacity(0)] attribute indicates no inline capacity hint; buffer memory management is left to the ECS runtime.