Game.Buildings.GarbageFacility
Assembly: Game
Namespace: Game.Buildings
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents the ECS component data for a garbage facility in Cities: Skylines 2. Tracks transfer request entities (deliver/receive/target), facility flags, garbage accept/deliver priorities and a processing rate. Implements custom versioned serialization/deserialization to maintain save compatibility across engine/game data format versions. Use this component on an Entity to store building-specific garbage service state.
Fields
-
public Entity m_GarbageDeliverRequest
Contains an Entity reference representing the outgoing (deliver) transfer request. Serialized only for newer save versions (reader.context.version >= Version.transferRequestRefactoring). In older versions this field is absent. -
public Entity m_GarbageReceiveRequest
Contains an Entity reference representing the incoming (receive) transfer request. Serialized only for newer save versions (reader.context.version >= Version.transferRequestRefactoring). In older versions this field is absent. -
public Entity m_TargetRequest
Entity reference to a target transfer request (used when service requests are reversed). Present/read when reader.context.version >= Version.reverseServiceRequests2. -
public GarbageFacilityFlags m_Flags
Flags describing facility state/behavior. Serialized as a single byte in file IO (cast to/from byte during Serialize/Deserialize). The raw byte is read into a temporary and then assigned/cast to this enum at the end of Deserialize. -
public float m_AcceptGarbagePriority
Priority value for accepting garbage. Only serialized/read when reader.context.version >= Version.garbageFacilityRefactor. In older versions priorities were stored differently (an int) and are skipped here. -
public float m_DeliverGarbagePriority
Priority value for delivering garbage. Same versioning rules as m_AcceptGarbagePriority (requires Version.garbageFacilityRefactor). -
public int m_ProcessingRate
Processing rate for the facility (int). This field is read/written only when reader.context.version >= Version.powerPlantConsumption (i.e., introduced at/after that version).
Notes on versioned serialization: - The Serialize method writes the fields in a fixed order (deliver, receive, target, flags(byte), accept/deliver priorities, processingRate). - Deserialize uses multiple version checks to read only the fields present for the save version being loaded. There is also a special-case read of a float between Version.garbageProcessing and Version.powerPlantConsumption that is ignored (read into a discard), preserving compatibility with an intermediate format.
Properties
- This struct defines no public properties; all state is stored in public fields.
Constructors
public GarbageFacility()
No explicit constructor is defined in source; the struct uses the default value-type constructor. Fields default to their type zero values (Entity.Null for entities, 0 for numeric fields, enum default (0) for flags). Initialize fields explicitly when creating an instance if non-default values are required.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component state to the provided writer in the following sequence:- m_GarbageDeliverRequest (Entity)
- m_GarbageReceiveRequest (Entity)
- m_TargetRequest (Entity)
- m_Flags as a byte
- m_AcceptGarbagePriority (float)
- m_DeliverGarbagePriority (float)
- m_ProcessingRate (int)
Note: Serialize unconditionally writes the above fields; compatibility is managed by the paired Deserialize implementation and the save version.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads component state from reader with many conditional branches depending on reader.context.version:- If version >= Version.transferRequestRefactoring: reads m_GarbageDeliverRequest and m_GarbageReceiveRequest; else an older format may have a different layout (a discarded read occurs for some intermediate versions).
- If version >= Version.reverseServiceRequests2: reads m_TargetRequest.
- Always reads a byte used for flags (value2) and assigns to m_Flags at the end.
- If version >= Version.garbageFacilityRefactor: reads m_AcceptGarbagePriority and m_DeliverGarbagePriority as floats; otherwise reads and discards an int (legacy format).
- If Version.garbageProcessing <= version < Version.powerPlantConsumption: reads and discards a float (legacy/intermediate field).
- If version >= Version.powerPlantConsumption: reads m_ProcessingRate (int).
The method ensures backward/forward compatibility with saved game data across multiple refactors of transfer/request fields and processing-related fields.
Usage Example
// Example: creating and attaching a GarbageFacility to an entity using an EntityManager
var facility = new GarbageFacility
{
m_GarbageDeliverRequest = Entity.Null,
m_GarbageReceiveRequest = Entity.Null,
m_TargetRequest = Entity.Null,
m_Flags = GarbageFacilityFlags.None,
m_AcceptGarbagePriority = 0f,
m_DeliverGarbagePriority = 0f,
m_ProcessingRate = 1
};
entityManager.AddComponentData(buildingEntity, facility);
// When saving/loading, the game's serializer will call Serialize/Deserialize above.
// When modifying serialization compatibility, update the version checks in Deserialize accordingly.