Skip to content

Game.Routes.RouteInfo

Assembly:
Most likely Assembly-CSharp (game runtime). Adjust if your mod compiles to a different assembly.

Namespace: Game.Routes

Type:
struct

Base:
Implements: IComponentData, IQueryTypeParameter, ISerializable

Summary:
RouteInfo is an ECS component (Unity.Entities) that stores compact information about a route: its duration, distance and flags. It implements ISerializable to support save/load and is intended to be used as a component in entity queries (IQueryTypeParameter). The flags are serialized as a single byte and deserialization of flags is conditional on the saved data version (backward-compatible).


Fields

  • public float m_Duration
    Holds the route duration (in seconds or game-time units). Serialized first by Serialize; deserialized into this field by Deserialize.

  • public float m_Distance
    Holds the route distance (units consistent with game metrics). Serialized second by Serialize; deserialized into this field by Deserialize.

  • public RouteInfoFlags m_Flags
    Holds route-related flags (enum RouteInfoFlags). During serialization the flags are written as a byte (writer.Write((byte)flags)). On deserialization the flags are only read if the reader.context.version is at least Version.transportLinePolicies — older save versions will not contain this byte and m_Flags remains at its default value.

Properties

  • None.
    This struct exposes only public fields and no C# properties.

Constructors

  • public RouteInfo() (default struct constructor)
    There is no explicit constructor in the source. Use the default struct initializer or object initializer to set m_Duration, m_Distance and m_Flags. Example:
var route = new RouteInfo {
    m_Duration = 120f,
    m_Distance = 3.5f,
    m_Flags = RouteInfoFlags.None
};

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the fields in order: m_Duration (float), m_Distance (float), and m_Flags as a byte. The flags are cast to byte before writing: writer.Write((byte)flags). This produces a compact representation suitable for saves.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads m_Duration and m_Distance in the same order they were written. Then, only if reader.context.version >= Version.transportLinePolicies, reads a byte and assigns it to m_Flags (cast from byte). This preserves backward compatibility with older save versions that lack the flags byte.

Usage Example

// Create and initialize a RouteInfo component
var route = new RouteInfo {
    m_Duration = 95.0f,
    m_Distance = 4.2f,
    m_Flags = RouteInfoFlags.Active | RouteInfoFlags.HasStops
};

// Example: serializing (pseudo-code; actual writer comes from game save system)
writer.Write(route.m_Duration);
writer.Write(route.m_Distance);
writer.Write((byte)route.m_Flags);

// Example: deserializing (pseudo-code; actual reader comes from game load system)
RouteInfo loaded = default;
reader.Read(out loaded.m_Duration);
reader.Read(out loaded.m_Distance);
if (reader.context.version >= Version.transportLinePolicies) {
    reader.Read(out byte flagsByte);
    loaded.m_Flags = (RouteInfoFlags)flagsByte;
}

Notes: - Because RouteInfo implements IComponentData it can be attached to entities in the Unity DOTS world and used in ECS systems and queries. - The conditional read for m_Flags is important for compatibility — if you add new flag bits in a mod, ensure save versioning is handled appropriately so older saves remain loadable.