Skip to content

Game.Vehicles.TrainBogieCache

Assembly:
Assembly-CSharp (game assembly where most runtime types live)

Namespace: Game.Vehicles

Type:
public struct TrainBogieCache

Base:
Colossal.Serialization.Entities.ISerializable

Summary:
A compact, serializable cache struct that holds the lane reference and curve-position data for a train bogie (wheelset) and optional lane flags. Used by the train/vehicle systems to persist or transfer per-bogie lane information. The struct implements the game's ISerializable pattern so instances can be written to and read from the game's serialization streams.


Fields

  • public Unity.Entities.Entity m_Lane
    Holds the Entity reference of the lane the bogie is associated with. Serialized/deserialized as an Entity via the Colossal.Serialization entities support.

  • public Unity.Mathematics.float2 m_CurvePosition
    Stores curve-position data for the bogie as a float2. Note: constructors populate this field from different components (e.g., .xw or .xx) depending on the source type, so the two components may carry different semantic meanings in context.

  • public TrainLaneFlags m_LaneFlags
    Bitflags describing additional lane attributes for the bogie. Serialized as a uint.

Properties

  • None.
    This struct exposes fields directly and does not provide C# properties.

Constructors

  • public TrainBogieCache(TrainBogieLane lane)
    Creates a cache entry from a TrainBogieLane instance. Copies lane entity, takes the source curve position as lane.m_CurvePosition.xw (x and w components mapped into the float2), and copies lane flags.

  • public TrainBogieCache(PathElement pathElement)
    Creates a cache entry from a PathElement. Sets m_Lane = pathElement.m_Target, m_CurvePosition = pathElement.m_TargetDelta.xx (uses the x component duplicated into both components of the float2), and clears m_LaneFlags to 0.

  • public TrainBogieCache(Entity lane, float curvePosition)
    Creates a cache entry directly from an Entity and a single float curvePosition. Stores the curvePosition into the float2 and clears m_LaneFlags to 0.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the instance to the provided writer in the following order: Entity (m_Lane), float2 (m_CurvePosition), and m_LaneFlags as uint. Compatible with the Colossal.Serialization IWriter implementations used by the game.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the instance from the provided reader in the same order: Entity, float2, then uint (converted into TrainLaneFlags). Uses ref locals to populate the fields.

Usage Example

// create from a TrainBogieLane
TrainBogieLane sourceLane = /* obtain from train system */;
TrainBogieCache cacheFromLane = new TrainBogieCache(sourceLane);

// create from a PathElement
PathElement pe = /* obtained from pathfinding */;
TrainBogieCache cacheFromPath = new TrainBogieCache(pe);

// create directly
Entity laneEntity = /* some lane entity */;
float curvePos = 0.25f;
TrainBogieCache directCache = new TrainBogieCache(laneEntity, curvePos);

// serializing (inside a serializer that provides an IWriter)
void WriteCache<TWriter>(TWriter writer, in TrainBogieCache cache) where TWriter : IWriter
{
    cache.Serialize(writer);
}

// deserializing (inside a deserializer that provides an IReader)
TrainBogieCache ReadCache<TReader>(TReader reader) where TReader : IReader
{
    TrainBogieCache cache = default;
    cache.Deserialize(reader);
    return cache;
}

Notes: - The struct is intended for efficient storage and I/O; fields are public and not validated during serialization. - Be mindful of which component of the float2 holds which semantic value — the struct's constructors map components differently depending on source types (TrainBogieLane vs PathElement).