Skip to content

Game.Prefabs.PublicTransportVehicleData

Assembly: Assembly-CSharp (game code)
Namespace: Game.Prefabs

Type: struct

Base: System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents configuration data for a public transport vehicle prefab in Cities: Skylines 2. Stores transport type, passenger capacity, purpose flags and maintenance range. The struct is used as an ECS component / query parameter and supports custom binary serialization via Colossal.Serialization (IWriter / IReader). The serialized layout and order are important for save/load and network compatibility.


Fields

  • public TransportType m_TransportType
    Specifies the vehicle's transport category (e.g., Bus, Tram, Metro). Serialized as an sbyte. Used to differentiate behavior and visuals for different transport systems.

  • public int m_PassengerCapacity
    Maximum number of passengers the vehicle can carry. Serialized as an int. Typical values are non-negative integers (0+).

  • public PublicTransportPurpose m_PurposeMask
    Flags describing the vehicle's purposes (a bitmask enum). Serialized as a uint. Use this to restrict or indicate what routes / passenger types the vehicle serves.

  • public float m_MaintenanceRange
    Range (in game units/meters) used for maintenance/servicing logic. Serialized as a float.

Properties

  • This type exposes no C# properties; it only contains public fields and implements interfaces for ECS and serialization.

Constructors

  • public PublicTransportVehicleData(TransportType type, int passengerCapacity, PublicTransportPurpose purposeMask, float maintenanceRange)
    Initializes a new instance with the provided transport type, passenger capacity, purpose mask and maintenance range.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the struct fields to the supplied writer in the following order and formats:
  • m_TransportType as sbyte
  • m_PurposeMask as uint
  • m_PassengerCapacity as int
  • m_MaintenanceRange as float This ordering must be preserved when deserializing.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads data in the same order written by Serialize and reconstructs the struct. Implementation reads an sbyte, a uint, then the int and float by reference, and finally assigns the enum-typed fields from the read integers.

Notes: - The implementation casts enums to/from primitive integer types when serializing/deserializing. Ensure enum underlying sizes match assumptions if modifying enums. - The Deserialize method reads into the primitive backing fields (int/float) by reference before assigning the enum fields.

Usage Example

// Create instance
var data = new PublicTransportVehicleData(
    TransportType.Bus,            // transport type
    50,                           // passenger capacity
    PublicTransportPurpose.Passenger, // purpose mask (flags)
    120f                          // maintenance range
);

// Serialize (example - using an IWriter implementation)
var writer = /* obtain IWriter implementation */;
data.Serialize(writer);

// Deserialize (example - using an IReader implementation)
var reader = /* obtain IReader implementation */;
var loaded = new PublicTransportVehicleData();
loaded.Deserialize(reader);

// Use as ECS component/query parameter
// e.g., add to entity or use in query where appropriate

Additional tips: - When modding, keep the serialization order stable to avoid savegame incompatibilities. - If you add fields, consider versioning or writing a compatibility layer so old saves can still load.