Game.Buildings.Building
Assembly: Assembly-CSharp (game assembly)
Namespace: Game.Buildings
Type: struct
Base: System.ValueType
Summary: A Unity ECS component representing a building instance in the game's entity map. Implements IComponentData so it can be attached to entities, IQueryTypeParameter to be used in ECS queries, and ISerializable to participate in the game's custom serialization pipeline. The struct stores a reference to a road edge entity, a curve position along that edge, an options bitmask, and flags describing building state/behavior.
Fields
-
public Entity m_RoadEdge
Reference to an Entity representing the connected road edge. This is used to link the building to the road network. When serialized, this Entity is written/read through the game's Colossal.Serialization system. -
public float m_CurvePosition
A floating point value indicating the position along the road curve where the building is placed. Serialized as a float. -
public uint m_OptionMask
A bitmask of building options (specific bits correspond to various building options/features). This field is conditionally read during deserialization depending on the saved data version (see Methods). -
public BuildingFlags m_Flags
Flags enum describing additional building state (creation flags, notification flags, etc.). When serialized it is written as a single byte; when deserializing it is only read for newer save versions (see Methods).
Properties
- None. This type exposes only public fields and relies on default struct constructor semantics.
Constructors
public Building()
Implicit default (value) constructor. The struct does not define an explicit constructor; fields will be default-initialized (Entity = default, floats = 0, uint = 0, enum = default).
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component fields into the provided writer in a fixed order:- m_RoadEdge (Entity)
- m_CurvePosition (float)
- m_OptionMask (uint)
- m_Flags (written as a single byte) Notes:
- The IWriter implementation used by the game handles entity remapping and other serialization details.
-
m_Flags is cast to byte before writing; only the low 8 bits are persisted by this implementation.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads fields back from the provided reader. The deserialization uses save-version checks to maintain backward compatibility: - Always reads m_RoadEdge and m_CurvePosition.
- Reads m_OptionMask only if reader.context.version >= Version.buildingOptions.
- Reads m_Flags (as a single byte cast back to BuildingFlags) only if reader.context.version >= Version.companyNotifications. Notes:
- reader.context.version is the saved-game format version; these conditional reads allow older saves without those fields to deserialize cleanly.
- The method reads directly into the struct's fields by reference (ref), matching how the game expects ISerializable implementations to behave.
Implementation details: - The struct implements ISerializable from Colossal.Serialization.Entities, so the game's save/load system will call Serialize/Deserialize automatically when persisting entities with this component. - The IQueryTypeParameter and IComponentData implementations allow this struct to participate in ECS queries and be stored in component data arrays.
Usage Example
// Create and attach the Building component to an entity
var buildingComponent = new Game.Buildings.Building {
m_RoadEdge = roadEdgeEntity, // some existing Entity referencing a road edge
m_CurvePosition = 0.5f, // position halfway along the curve
m_OptionMask = 0u, // no options set (or set bits as needed)
m_Flags = BuildingFlags.None // or other flags defined in BuildingFlags
};
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity buildingEntity = entityManager.CreateEntity();
entityManager.AddComponentData(buildingEntity, buildingComponent);
// Serialization is handled by the game engine via ISerializable.
// When you add or change fields in this struct, be careful to maintain
// version checks in Deserialize so older saves remain compatible.
Additional notes for modders: - Do not assume the presence of m_OptionMask or m_Flags in older save files — the Deserialize method already guards reads by save version. If you extend this struct in a mod, follow the same pattern (check reader.context.version before reading newly-added fields). - Because m_Flags are serialized as a single byte, only values that fit within a byte are preserved; expanding the enum beyond 8 meaningful bits without updating serialization will truncate data. If you need more bits, update the serialization format and use a higher save version constant. - Use the engine's Entity remapping and serialization APIs when creating custom entities that reference other game entities (for example, road edges) so references are preserved across save/load and prefab instancing.