Skip to content

Game.Prefabs.RoadData

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

Type: struct

Base: System.ValueType

Summary:
RoadData is an ECS component (IComponentData) used to describe basic road properties for a prefab in the game's prefab system. It also implements ISerializable for Colossal's serialization system and IQueryTypeParameter for use in queries. Only the speed limit and flags are serialized by this type; the prefab entity reference (m_ZoneBlockPrefab) is a runtime reference and is not written by Serialize/Deserialize.


Fields

  • public Unity.Entities.Entity m_ZoneBlockPrefab
    This is an Entity reference (prefab) for a zone/side block associated with the road. It is not serialized by the type's Serialize/Deserialize methods and thus is considered a runtime-only reference; it must be (re)assigned by code when loading if needed.

  • public float m_SpeedLimit
    The speed limit value for the road. This value is written and read by the Serialize/Deserialize implementations (as a single float).

  • public RoadFlags m_Flags
    An enum storing flags describing road characteristics (e.g., lanes, restrictions, orientation). This field is serialized as a uint. The concrete members of RoadFlags are defined elsewhere in the codebase — consult that enum for valid flag values and meanings.

Properties

  • This type defines no properties. It exposes public fields and implements interfaces.

Constructors

  • public RoadData()
    The default value-type constructor. When created with the default constructor or via value initialization, fields have default values: m_ZoneBlockPrefab is Entity.Null, m_SpeedLimit is 0f, and m_Flags is the default enum value (usually 0). Initialize fields explicitly before adding the struct as a component if non-defaults are required.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : Colossal.Serialization.Entities.IWriter
    Writes the persisted data for this component into the provided writer. Current implementation writes:
  • m_SpeedLimit as a float
  • m_Flags cast to uint

Note: m_ZoneBlockPrefab is not written. The order and types are important for compatibility when reading back the data.

  • public void Deserialize<TReader>(TReader reader) where TReader : Colossal.Serialization.Entities.IReader
    Reads persisted data from the reader and assigns to this instance. Current implementation reads:
  • a float into m_SpeedLimit
  • a uint which is cast to RoadFlags and assigned to m_Flags

After deserialization, code should restore or reassign runtime references (e.g., m_ZoneBlockPrefab) as needed, since they are not included in the serialized form.

Usage Example

// Create and initialize a RoadData component, add it to an entity, and serialize it.
var roadData = new RoadData {
    m_ZoneBlockPrefab = Entity.Null, // set to a valid prefab Entity when available
    m_SpeedLimit = 50f,
    m_Flags = RoadFlags.Default // replace with appropriate flags
};

// Add to an entity (EntityManager variable assumed available)
// entityManager.AddComponentData(roadEntity, roadData);

// Serialize (writer variable assumed to implement IWriter)
roadData.Serialize(writer);

// To deserialize:
var loaded = new RoadData();
loaded.Deserialize(reader);
// After deserialization, reassign runtime-only references such as m_ZoneBlockPrefab if needed.

{{ Notes and tips: - Because m_ZoneBlockPrefab is not serialized, loading code should resolve prefab Entity references after Deserialize (for example, by looking up prefabs by name or id). - Preserve the serialization order and types when updating Serialize/Deserialize to maintain save/load compatibility. - As an IComponentData struct, use EntityManager or systems to add/remove and query RoadData components. }}