Skip to content

Game.TrackLane

Assembly: Game
Namespace: Game.Net

Type: struct

Base: System.ValueType (implements Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable)

Summary: TrackLane is an ECS component that represents per-lane data for rail/track lanes in the game's network system. It stores a reference to an access restriction entity (optional), bitflags describing lane behavior, and numeric values for the lane's speed limit and curviness. The struct implements ISerializable to control how its data is persisted and restored, including a version check for compatibility when reading older saves.


Fields

  • public Unity.Entities.Entity m_AccessRestriction Reference to an Entity that defines access restrictions for this lane (for example, a pathfinding restriction entity). This field is conditionally deserialized depending on the save/version feature flag.

  • public TrackLaneFlags m_Flags Bitflags (enum) describing lane properties (behavioral flags such as allowed vehicle types, special lane attributes, etc.). Stored as a uint when serialized.

  • public float m_SpeedLimit Per-lane speed limit value (in game units). Serialized as a float.

  • public float m_Curviness Per-lane curviness parameter (how curvy the lane is). Serialized as a float.

Properties

  • (none)

Constructors

  • public TrackLane() Default value-type constructor produced by the C# compiler. All fields are default-initialized (Entity = default/None, flags = 0, numeric fields = 0.0f).

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter Writes the component fields to the provided writer in the following order:
  • m_AccessRestriction (Entity)
  • m_Flags (written as a uint)
  • m_SpeedLimit (float)
  • m_Curviness (float)

Note: The implementation casts TrackLaneFlags to uint for compact storage.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader Restores the component from the reader. Behavior:
  • If reader.context.version >= Version.pathfindRestrictions, it reads m_AccessRestriction (Entity). This preserves compatibility with older saves where that field did not exist.
  • Reads a uint into a temporary and later casts it to TrackLaneFlags to populate m_Flags.
  • Reads m_SpeedLimit and m_Curviness (floats) in the same order as written.

Important: The version check ensures backward/forward compatibility; callers should be aware that the access restriction field might not be present in older save data.

Usage Example

// Example: creating and populating a TrackLane component (used in ECS or serialization)
TrackLane lane = new TrackLane();
lane.m_AccessRestriction = Entity.Null; // or a real Entity reference
lane.m_Flags = TrackLaneFlags.None;     // set flags appropriate for this lane
lane.m_SpeedLimit = 20f;
lane.m_Curviness = 0.5f;

// When the game's serializer runs it will invoke lane.Serialize(writer).
// On load, lane.Deserialize(reader) will restore values, honoring the version check
// for m_AccessRestriction.

Additional notes: - Because TrackLane implements ISerializable, it participates in the game's custom serialization pipeline. When writing mods that interact with entity serialization you should preserve the same read/write order and respect the version check to avoid corrupting save files. - The m_AccessRestriction field references an Entity. When manipulating or creating such references in code, ensure proper entity remapping if moving data between worlds or when emulating save/load behavior.