Skip to content

Game.Prefabs.PlaceholderBuildingData

Assembly: Game
Namespace: Game.Prefabs

Type: struct

Base: Implements IComponentData, IQueryTypeParameter, ISerializable

Summary:
PlaceholderBuildingData is a lightweight ECS component used to attach a "placeholder" building reference and its building type to an entity. It is serializable via the Colossal.Serialization.Entities system so instances can be written to and read from save/stream data. Typical use is in prefab/zone systems where a placeholder entity references a zone prefab and the intended BuildingType for later processing (spawning real buildings, previews, etc.).


Fields

  • public Unity.Entities.Entity m_ZonePrefab
    Reference to the zone prefab Entity used as the placeholder. When serialized this Entity is written via the Colossal serialization writer/reader so the link can be restored on load.

  • public BuildingType m_Type
    Enum value describing the building type/category associated with this placeholder (e.g., Residential, Commercial, Industrial, Office). Serialized as an integer.

Properties

  • This type defines no managed properties. It exposes two public fields and relies on its interface implementations for serialization/querying.

Constructors

  • public PlaceholderBuildingData()
    Default value-type constructor (implicit). When created without initialization, m_ZonePrefab will be the default Entity value and m_Type will be the default enum value (usually 0). For predictable behavior initialize fields explicitly when creating instances.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
    Writes the component data to a serializer. Implementation writes the m_ZonePrefab Entity first, then writes the m_Type as an integer. This ensures the Entity reference and the building type are saved in a stable order.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader
    Reads the component data from a deserializer. Implementation reads an Entity into m_ZonePrefab and then reads an int which is cast back to BuildingType for m_Type. Order must match Serialize.

Usage Example

// Create and initialize the component
var placeholder = new PlaceholderBuildingData {
    m_ZonePrefab = zonePrefabEntity,  // an Entity obtained elsewhere
    m_Type = BuildingType.Residential
};

// Example: serializing the component with a writer
writer.Write(placeholder.m_ZonePrefab);
writer.Write((int)placeholder.m_Type);

// Example: deserializing into an instance (inside a reader context)
var read = new PlaceholderBuildingData();
reader.Read(out read.m_ZonePrefab);
reader.Read(out int typeValue);
read.m_Type = (BuildingType)typeValue;

// Example: adding the component to an entity (Entities API)
entityManager.AddComponentData(someEntity, placeholder);

Notes: - Keep serialize/deserialize order consistent to avoid data corruption. - Because this is an IComponentData struct, store minimal data (Entity + enum) to keep archetype sizes small and queries efficient. - The IQueryTypeParameter marker indicates it can be used in certain ECS query contexts (depending on the surrounding codebase conventions).