Skip to content

Game.Prefabs.TrackLaneData

Assembly:
Game (assembly inferred from namespace)

Namespace:
Game.Prefabs

Type:
struct

Base:
Implements: IComponentData, IQueryTypeParameter, ISerializable

Summary:
Represents lane-specific data for a track prefab. Holds references to related prefab entities, the track type flags for this lane, and a curviness limit. Implements Colossal's ISerializable to control how lane data is written/read (only the track type is serialized). Commonly used as a component on entities that represent track lanes in the game's ECS.


Fields

  • public Entity m_FallbackPrefab
    Reference to a fallback prefab Entity used if the primary lane prefab is unavailable. Typically points to an existing prefab Entity that can be used as a substitute at runtime.

  • public Entity m_EndObjectPrefab
    Entity reference for an end-of-track object (for example a cap, buffer or terminator object that should be placed at the end of the lane).

  • public TrackTypes m_TrackTypes
    Flags/enumeration describing the type(s) of track this lane supports. This value is serialized as a single byte in Serialize/Deserialize (casting to/from byte).

  • public float m_MaxCurviness
    Maximum allowed curviness for the lane. Note: this is not serialized by the provided Serialize implementation; Deserialize sets this to float.MaxValue by default.

Properties

  • None (no public properties defined on this struct)

Constructors

  • public TrackLaneData() (implicit default struct constructor)
    No explicit constructors are declared in the source. The struct uses the default value constructor; fields should be explicitly assigned when creating an instance unless relying on default (zero/null) values. After deserialization, m_MaxCurviness is set to float.MaxValue.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the track type to the provided writer as a single byte:
  • writer.Write((byte)m_TrackTypes); Note that m_FallbackPrefab, m_EndObjectPrefab and m_MaxCurviness are not serialized by this method.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads a single byte from the reader and assigns it to m_TrackTypes (casting from byte). Also sets m_MaxCurviness = float.MaxValue. Implementation details:

  • reader.Read(out byte value);
  • m_TrackTypes = (TrackTypes)value;
  • m_MaxCurviness = float.MaxValue;

Generics: both methods are generic over TWriter/TReader constrained to IWriter/IReader respectively (Colossal.Serialization.Interfaces).

Usage Example

// Example: create and attach TrackLaneData to an entity
var laneData = new TrackLaneData
{
    m_FallbackPrefab = fallbackPrefabEntity,
    m_EndObjectPrefab = endObjectPrefabEntity,
    m_TrackTypes = TrackTypes.Rail, // example enum value
    m_MaxCurviness = 0.75f
};

EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
em.AddComponentData(laneEntity, laneData);

// Serialization example (manual use of writer)
writer.Write((byte)laneData.m_TrackTypes);

// After deserialization the curviness will be set to float.MaxValue by the struct:
TrackLaneData deserialized;
reader.Read(out byte value);
deserialized.m_TrackTypes = (TrackTypes)value;
deserialized.m_MaxCurviness = float.MaxValue;

Notes: - Only the m_TrackTypes field is serialized by the provided Serialize method. If you need to persist prefab references or m_MaxCurviness across network/save, extend the serialization logic accordingly. - The struct implements IQueryTypeParameter, so it can be used in queries/filters where that API is required in the ECS usage patterns of the game.