Skip to content

Game.Buildings.GarbageProducer

Assembly: Assembly-CSharp.dll
Namespace: Game.Buildings

Type: struct

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: Represents a building-side garbage producer component used by the game's ECS (Unity.Entities). Holds a link to a collection request entity, the amount of garbage queued/produced, flags describing producer state, and a dispatch index used for request routing. Implements Colossal's serialization interfaces to persist/load component data across saves and support versioned compatibility.


Fields

  • public Entity m_CollectionRequest Reference to the Entity that represents the garbage collection request associated with this producer (if any). Used to match the building's produced garbage with the active collection request entity.

  • public int m_Garbage Integer amount of garbage currently produced/queued by the building. This is the primary numeric value used by collection logic to determine how much needs to be picked up.

  • public GarbageProducerFlags m_Flags Bitflags (enum) describing state for the garbage producer (e.g., state markers such as active/inactive, priority markers, or other producer-specific flags). Note: this field is read from saved data only when the reader context version is at or above Version.garbageProducerFlags.

  • public byte m_DispatchIndex A small index value used when dispatching requests (likely an index into a dispatcher table or queue). This field is read from saved data only when the reader context version is at or above Version.requestDispatchIndex.

Properties

  • None. This struct exposes only public fields; there are no properties defined.

Constructors

  • implicit parameterless constructor Structs in C# have an implicit parameterless constructor that zero-initializes fields. No explicit constructors are declared in the source.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter Writes the component's fields to the provided writer in the following order:
  • m_CollectionRequest (Entity)
  • m_Garbage (int)
  • m_Flags (written as a byte)
  • m_DispatchIndex (byte) This method is used when saving/serializing the entity/component to persistent storage.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader Reads component data from the provided reader. It reads the collection request Entity and the garbage int unconditionally. The flags and dispatch index are read conditionally based on the save data version:

  • If reader.context.version >= Version.garbageProducerFlags: reads a byte and casts it to GarbageProducerFlags into m_Flags.
  • If reader.context.version >= Version.requestDispatchIndex: reads a byte into m_DispatchIndex. Uses ref locals to read directly into the struct fields to avoid extra copies.

Usage Example

// Example: adding a GarbageProducer component to an entity and initializing fields.
Entity myBuildingEntity = entityManager.CreateEntity();
GarbageProducer gp = new GarbageProducer
{
    m_CollectionRequest = Entity.Null,
    m_Garbage = 120, // e.g., 120 units of garbage produced
    m_Flags = GarbageProducerFlags.None,
    m_DispatchIndex = 0
};
entityManager.AddComponentData(myBuildingEntity, gp);

// During save/load, the game's serialization system will call Serialize/Deserialize.