Skip to content

Game.Vehicles.Train

Assembly: Assembly-CSharp.dll
Namespace: Game.Vehicles

Type: struct Train

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents the lightweight ECS component for a train vehicle. It stores a bitmask of TrainFlags that describe configuration/state bits for a train (for example equipment like pantographs, or other train-specific flags). The struct is designed to be serialized/deserialized via the game's generic serialization interfaces and includes a compatibility fallback: older save/prefab versions that predate the addition of certain flags get the Pantograph flag added during deserialization.


Fields

  • public TrainFlags m_Flags
    Stores the TrainFlags bitmask for this train component. Values come from the TrainFlags enum (not included here). The field is used both at runtime (ECS queries/system logic) and for persisting the train's flag state via ISerializable.

Properties

  • This type does not define any properties.

Constructors

  • public Train(TrainFlags flags)
    Initializes a Train instance with the provided flags value. Typical usage is to create a component with an initial flag set (or TrainFlags.None) before adding it to an entity.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the m_Flags value as a uint to the provided writer. The serializer is generic to the game's writer abstraction so this method integrates with the engine's save/load and prefab pipelines.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads a uint from the reader, casts it back to TrainFlags and assigns it to m_Flags. After reading, it performs a compatibility step: if the reader's context version is older than Version.trainPrefabFlags, it sets the Pantograph flag (m_Flags |= TrainFlags.Pantograph) to preserve expected behavior for older data that did not store that flag explicitly.

Notes: - The generic reader/writer types are constrained to IReader/IWriter and rely on the reader.context.version integer to detect format version. - Implementing IQueryTypeParameter indicates this component can be used directly in ECS query type parameters (marker for the query system).

Usage Example

// Construct a Train component with no flags:
var train = new Train(TrainFlags.None);

// Set a flag (example):
train.m_Flags |= TrainFlags.Pantograph;

// Serializing (pseudocode — actual writer type is provided by the engine):
// using (var writer = GetGameWriter(...))
// {
//     train.Serialize(writer);
// }

// Deserializing (pseudocode — actual reader type/context provided by the engine):
// Train loaded = default;
// using (var reader = GetGameReader(...))
// {
//     loaded.Deserialize(reader);
//     // loaded.m_Flags now contains the saved flags, and older versions will have
//     // TrainFlags.Pantograph added automatically if necessary.
// }