Game.Vehicles.GarbageTruck
Assembly:
Cities: Skylines 2 game assembly (exact assembly name not provided in source)
Namespace:
Game.Vehicles
Type:
struct
Base:
System.ValueType
Implements: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents the per-vehicle component data for a garbage truck in the ECS world. Stores the truck's current service target, state flags, counts and garbage amounts, and timing information used by the vehicle/garbage systems and the save/load subsystem. The struct is serializable for game save compatibility and is intended to be used in Unity's DOTS/ECS workflows.
Fields
-
public Entity m_TargetRequest
Entity ID for the current service request target (e.g., the garbage bin/collection request). May be Entity.Null when there is no active target. -
public GarbageTruckFlags m_State
Flags enum describing the truck's current state (traveling, collecting, returning, etc.). Serialized as a uint. -
public int m_RequestCount
The number of outstanding or assigned service requests for this truck. Used by routing/assignment logic. -
public int m_Garbage
Current amount of garbage onboard the truck. -
public int m_EstimatedGarbage
Estimated amount of garbage expected (used by route planning and request reversing logic). Written/read conditionally depending on save version. -
public float m_PathElementTime
Time spent on the current path element (used for path-following / animation / timing logic).
Properties
- This struct does not expose properties. All data is stored in public fields to be compatible with DOTS/ECS and serialization patterns.
Constructors
public GarbageTruck(GarbageTruckFlags flags, int requestCount)
Initializes a new GarbageTruck instance. Sets:- m_TargetRequest = Entity.Null
- m_State = flags
- m_RequestCount = requestCount
- m_Garbage = 0
- m_EstimatedGarbage = 0
- m_PathElementTime = 0f
Use this constructor when creating a new component instance to set initial state and request count.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component data to the provided writer in a specific order:- m_TargetRequest (Entity)
- m_EstimatedGarbage (int)
- m_State (written as uint)
- m_RequestCount (int)
- m_Garbage (int)
- m_PathElementTime (float)
This method is used by the game's save system. The order and types must match what Deserialize expects for compatibility.
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads component data from the reader. The method handles save-version compatibility:- If reader.context.version >= Version.reverseServiceRequests2, it first reads:
- m_TargetRequest (Entity)
- m_EstimatedGarbage (int)
- Then it reads a uint that is interpreted as the serialized state value.
- Reads m_RequestCount (int), m_Garbage (int), m_PathElementTime (float).
- Finally sets m_State = (GarbageTruckFlags)value.
Be aware of the conditional read — older save versions may store fields in a different order or omit some fields; the version check ensures backward compatibility.
Notes: - Implementing ISerializable means these methods are used by the engine's serialization pipeline. - Implementing IComponentData makes this suitable for use as an ECS component (value type, no managed references). - Implementing IQueryTypeParameter allows this type to be used in ECS query signatures.
Usage Example
// Create a new GarbageTruck component with default values
var truck = new GarbageTruck(GarbageTruckFlags.None, requestCount: 0);
// Example: update fields directly (ECS systems typically do this)
truck.m_Garbage = 10;
truck.m_PathElementTime = 0f;
// Example: serialization (pseudocode — actual writer instance comes from engine)
using (var writer = GetGameWriter())
{
truck.Serialize(writer);
}
// Example: deserialization (pseudocode)
using (var reader = GetGameReader())
{
var loadedTruck = new GarbageTruck(GarbageTruckFlags.None, 0);
loadedTruck.Deserialize(reader);
// loadedTruck now contains values read from the save stream
}
Additional notes: - Because this is a struct used with ECS, avoid storing managed references inside it. - When modifying serialization order or fields, update version handling to preserve save compatibility (use Version.* checks as shown in Deserialize).