Game.Simulation.GarbageCollectionRequest
Assembly: Game (Assembly-CSharp)
Namespace: Game.Simulation
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a request to perform garbage collection for a specific Entity within the simulation. Carries the target Entity, a priority value used to order processing, option flags (GarbageCollectionRequestFlags), and a dispatch index used for request dispatch bookkeeping. Implements serialization so requests can be saved/loaded across game versions; the deserialization logic is version-aware and conditionally reads fields based on the saved version.
Fields
-
public Entity m_Target
The Entity that is the target of the garbage collection request. This is the simulation object that should be processed/removed when the garbage collection system handles this request. -
public int m_Priority
Integer priority for the request. Higher or lower values determine processing order relative to other requests (semantics defined by the garbage collection system). Set via the constructor. -
public GarbageCollectionRequestFlags m_Flags
Flags controlling specific behaviors for the request. Stored as a byte when serialized. The enum type GarbageCollectionRequestFlags is used to pass modifiers/options (e.g., special handling modes); consult that enum for available flags. -
public byte m_DispatchIndex
A small dispatch index value used by the request dispatching system (likely for tracking or de-duplication). Initialized to 0 in the constructor. Serialized as a single byte and only read from older saves when the version supports it.
Properties
- (none)
This type exposes no properties; it is a plain struct with public fields and implements ISerializable for custom serialization.
Constructors
public GarbageCollectionRequest(Entity target, int priority, GarbageCollectionRequestFlags flags)
Creates a new request with the specified target Entity, priority, and flags. The dispatch index is initialized to 0.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes the request into the provided writer in the following order:- Entity target (m_Target)
- int priority (m_Priority)
- byte flags (m_Flags cast to byte)
- byte dispatchIndex (m_DispatchIndex)
The method uses the generic IWriter from Colossal.Serialization.Entities to write values.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes the request from the reader. Reads fields in a version-aware manner:- Always reads m_Target and m_Priority.
- Reads m_Flags only if reader.context.version >= Version.industrialWaste (flags are written starting at that version).
- Reads m_DispatchIndex only if reader.context.version >= Version.requestDispatchIndex (dispatch index was added in that version). Uses Colossal.Serialization.Entities IReader and relies on reader.context.version to maintain backward compatibility.
Usage Example
// Create a new garbage collection request targeting an entity with priority 100 and default flags
Entity someEntity = /* obtain entity reference */;
var request = new GarbageCollectionRequest(someEntity, 100, GarbageCollectionRequestFlags.None);
// The struct can be added to an entity (as a component) or enqueued in whatever system accepts requests.
// Example (pseudocode, depends on the game's ECS usage):
// entityManager.AddComponentData(requestEntity, request);
Notes: - The struct is intended for use in the game's ECS-based simulation and is serializable for save/load compatibility. - Be mindful of version-dependent fields when creating custom save/load logic or attempting to interact with older save formats.