Skip to content

Game.Prefabs.TransportLineData

Assembly: Game
Namespace: Game.Prefabs

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary:
TransportLineData is an ECS component used by transport prefabs to store metadata for a transport line (vehicle/pathfinding settings, default timings, transport categories and size). It implements ISerializable to support custom binary (de)serialization for save/prefab data. Note that some runtime-only fields (e.g., notification Entity) are present but not necessarily serialized in all formats.


Fields

  • public Entity m_PathfindPrefab
    Holds the Entity prefab used for pathfinding (the pathfinding/AI prefab associated with the line).

  • public TransportType m_TransportType
    Enum describing the transport category (e.g., bus, tram, train — stored/written as an sbyte in serialization).

  • public float m_DefaultVehicleInterval
    Default time interval between vehicles on the line.

  • public float m_DefaultUnbunchingFactor
    Default unbunching factor used to reduce vehicle bunched-up behavior.

  • public float m_StopDuration
    Default time a vehicle stops at stops on this line.

  • public SizeClass m_SizeClass
    Size class of vehicles on this line (Large/Small/etc.). Serialized as a byte; when reading older formats that lack this tag, a default of SizeClass.Large is applied.

  • public bool m_PassengerTransport
    Flag indicating whether the line transports passengers.

  • public bool m_CargoTransport
    Flag indicating whether the line transports cargo.

  • public Entity m_VehicleNotification
    Entity used for vehicle notifications. Present in the struct but not handled uniformly by all serialization formats (not always written/read in older formats).

Properties

  • None.

Constructors

  • public TransportLineData()
    Implicit default parameterless constructor provided by the struct. Fields will have default CLR values (Entity = default, numeric = 0, bool = false, enum = default).

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes component data to the provided writer in the following order:
  • m_PathfindPrefab (Entity)
  • m_TransportType (as sbyte)
  • m_DefaultVehicleInterval (float)
  • m_DefaultUnbunchingFactor (float)
  • m_StopDuration (float)
  • m_PassengerTransport (bool)
  • m_CargoTransport (bool)
  • m_SizeClass (as byte) Note: size class is written as a byte at the end so newer save/prefab formats include it.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads component data from the reader in the order expected by Serialize. Behavior notes:

  • Reads m_PathfindPrefab, transport type (sbyte), default vehicle interval, unbunching factor, stop duration, passenger/cargo flags.
  • Assigns m_TransportType from the read sbyte.
  • For m_SizeClass, the reader checks reader.context.format.Has(FormatTags.BpPrefabData):
    • If the format supports the BpPrefabData tag, it reads a byte and assigns m_SizeClass from it.
    • Otherwise, it sets m_SizeClass = SizeClass.Large to preserve compatibility with older formats that lacked this field.
  • m_VehicleNotification is not read/written here (i.e., runtime-only or handled elsewhere).

Usage Example

// Adding the component to an entity (EntityManager API)
var transportData = new TransportLineData {
    m_PathfindPrefab = somePathfindEntity,
    m_TransportType = TransportType.Bus,
    m_DefaultVehicleInterval = 20f,
    m_DefaultUnbunchingFactor = 1.0f,
    m_StopDuration = 5f,
    m_SizeClass = SizeClass.Medium,
    m_PassengerTransport = true,
    m_CargoTransport = false,
    m_VehicleNotification = Entity.Null
};
entityManager.AddComponentData(lineEntity, transportData);

// Serialization example (internal game/prefab writer)
writer.Write(transportData.m_PathfindPrefab);
writer.Write((sbyte)transportData.m_TransportType);
writer.Write(transportData.m_DefaultVehicleInterval);
writer.Write(transportData.m_DefaultUnbunchingFactor);
writer.Write(transportData.m_StopDuration);
writer.Write(transportData.m_PassengerTransport);
writer.Write(transportData.m_CargoTransport);
writer.Write((byte)transportData.m_SizeClass);

// Deserialization notes:
// When reading, check for FormatTags.BpPrefabData; if missing, SizeClass will default to Large.

{{ Additional notes: - This component is intended for use with the game's ECS (Unity.Entities) systems and prefab save/load machinery. - When creating or modifying TransportLineData for modding/prefab compatibility, ensure you respect the serialization order and the FormatTags check for backward compatibility. }}