Skip to content

Game.Vehicles.ParkedTrain

Assembly: Assembly-CSharp
Namespace: Game.Vehicles

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents a parked train component for an entity in the game's ECS. Stores the parking location entity, references to the front and rear lane entities the parked train occupies, and the curve positions along those lanes. Implements ISerializable to support custom binary serialization/deserialization used by the game's save/load system. Commonly used by vehicle/rail systems to persist parked train state between frames and across saves.


Fields

  • public Entity m_ParkingLocation
    Holds the Entity that represents the parking location (station/platform/parking spot) where the train is parked.

  • public Entity m_FrontLane
    Entity reference to the lane used by the front of the parked train. Defaults to Entity.Null when not set.

  • public Entity m_RearLane
    Entity reference to the lane used by the rear of the parked train. Defaults to Entity.Null when not set.

  • public float2 m_CurvePosition
    Pair of float values representing curve positions along the front and rear lanes. Constructed so that x/y correspond to front/rear curve positions (see constructor that accepts TrainCurrentLane). Defaults to (0f, 0f).

Properties

  • This type exposes no C# properties; it uses public fields for data storage and implements ISerializable to handle persistence.

Constructors

  • public ParkedTrain(Entity location)
    Initializes a ParkedTrain with a parking location. Sets m_FrontLane and m_RearLane to Entity.Null and m_CurvePosition to 0f.

  • public ParkedTrain(Entity location, TrainCurrentLane currentLane)
    Initializes from a TrainCurrentLane (runtime lane state). Copies the parking location, sets m_FrontLane to currentLane.m_Front.m_Lane and m_RearLane to currentLane.m_Rear.m_Lane. Sets m_CurvePosition to a float2 containing the front and rear curve positions (taken from currentLane.m_Front.m_CurvePosition.y and currentLane.m_Rear.m_CurvePosition.y).

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component fields to the provided writer in the following order: m_ParkingLocation, m_FrontLane, m_RearLane, m_CurvePosition. Used by the game's serialization system to persist parked train data.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component fields from the provided reader into the struct's fields in the same order they were written. Uses ref locals to assign into fields directly.

Usage Example

// Create a parked-train component and add it to an entity
Entity parkingSpot = /* obtain parking spot entity */;
ParkedTrain parked = new ParkedTrain(parkingSpot);

// Or construct from runtime lane state
TrainCurrentLane laneState = /* obtain current lane state for a train */;
ParkedTrain parkedFromLane = new ParkedTrain(parkingSpot, laneState);

// Add to an entity via the EntityManager (example)
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity trainEntity = em.CreateEntity();
// attach parked-train component
em.AddComponentData(trainEntity, parked);

Notes and tips: - Because this is an IComponentData struct, it is used in ECS queries and systems. Access fields directly in jobs/systems. - Serialization follows a fixed field order; if you modify fields in future versions of the mod/game, ensure serialization compatibility or handle versioning. - The constructor that accepts TrainCurrentLane extracts the curve positions from nested front/rear structures — confirm the correct indices/values if the TrainCurrentLane structure changes in game updates.