Skip to content

Game.Objects.QuantityUpdateSystem

Assembly: Assembly-CSharp
Namespace: Game.Objects

Type: class

Base: GameSystemBase

Summary:
QuantityUpdateSystem is an ECS system that updates the Quantity component for entities (e.g. objects that visually represent amount/fullness). It schedules a Burst-compiled IJobChunk (UpdateQuantityJob) that iterates over entities with Quantity and various updated flags and computes a fullness value based on many possible sources: owner building storage, company/warehouse storage, delivery trucks, cargo vehicles, mail/garbage producers, work vehicles (map features and work amount), and other economy resource buffers. The job also resolves the effective owner entity by walking the Owner chain (skipping vehicles/creatures) to evaluate storage/producer data on the correct entity.


Fields

  • private EntityQuery m_QuantityQuery
    This EntityQuery selects entities that have a Quantity component and have been updated (Updated or BatchesUpdated) and are not Deleted/Destroyed. The system uses this query to schedule the chunk job only when relevant entities exist.

  • private EntityQuery m_PostConfigurationQuery
    Query used to access PostConfigurationData singleton (used to get mail accumulation tolerance).

  • private EntityQuery m_GarbageConfigurationQuery
    Query used to access GarbageParameterData singleton (used for garbage request/warning limits).

  • private TypeHandle __TypeHandle
    Container for ComponentTypeHandles, ComponentLookup and BufferLookup handles used by the job. It is initialized for the SystemState in OnCreateForCompiler.

  • private struct UpdateQuantityJob (nested)
    Burst-compiled IJobChunk that does the heavy lifting. It contains component handles and lookups for PrefabRef, Quantity, Temp, Owner, Vehicle, DeliveryTruck, WorkVehicle, Creature, MailProducer, GarbageProducer, storage/prefab data lookups and multiple BufferLookups. Execute(...) computes a new Quantity (byte fullness) for each chunk element by checking multiple data sources and writes the resulting Quantity back to the component array.

  • private struct TypeHandle (nested)
    Generated helper struct that contains the per-system ComponentTypeHandle/ComponentLookup/BufferLookup instances and an __AssignHandles method that initializes them from a SystemState.

Properties

  • None (the system does not expose public properties).

Constructors

  • public QuantityUpdateSystem()
    Default constructor. Marked with Preserve attribute elsewhere in code paths; constructs the system and relies on the base GameSystemBase initialization.

Methods

  • protected override void OnCreate() : System.Void
    Creates the entity queries used by the system (m_QuantityQuery, m_PostConfigurationQuery, m_GarbageConfigurationQuery) and calls RequireForUpdate(m_QuantityQuery) so the system only updates when relevant entities exist.

  • protected override void OnUpdate() : System.Void
    Builds and schedules the UpdateQuantityJob (Burst compiled) with all required ComponentTypeHandles, ComponentLookup and BufferLookup references, and passes in singletons (PostConfigurationData and GarbageParameterData). The returned JobHandle is stored to base.Dependency.

  • protected override void OnCreateForCompiler() : System.Void
    Called by generated code paths at compilation-time to assign query and handle state needed by the system. It calls __AssignQueries and initializes the __TypeHandle via __AssignHandles.

  • private void __AssignQueries(ref SystemState state) : System.Void
    Currently a small/generated helper used to register/assign queries for the compiled system. Present to satisfy generated/compiled code flow (no runtime query creation other than in OnCreate).

  • (nested) UpdateQuantityJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) : System.Void
    Per-chunk execution method. For each entity in the chunk it:

  • Resolves the relevant owner entity via GetOwner (handles Temp original overrides).
  • Reads QuantityObjectData from the prefab referenced by the Quantity object.
  • Checks multiple possible data sources (renters/warehouses, city service upkeep + storage, delivery trucks, mail producers, garbage producers, entity economy buffers/cargo vehicles, work vehicles for map features and resources).
  • Computes a fullness percentage as a byte (0–255) based on amounts and capacities; sets value.m_Fullness accordingly.
  • Clears the checked resource/map feature flag on the QuantityObjectData (sets to NoResource / None) to indicate it has been handled.

  • (nested) UpdateQuantityJob.GetOwner(Entity entity) : Entity
    Traverses owner chain using Owner components to find the "real" owner entity to evaluate. The traversal stops when an entity is a Vehicle or a Creature, otherwise it follows Owner.m_Owner. Returns the final owner entity.

Notes: - The job is Burst-compiled and uses Unity.Collections/Mathematics and ComponentLookups/BufferLookups for efficient data access. - The system reads many prefab data types (QuantityObjectData, DeliveryTruckData, WorkVehicleData, StorageCompanyData, SpawnableBuildingData, BuildingData, GarbageFacilityData, etc.) to determine resource types and capacities. - The computed fullness is stored as a byte where values typically map percent -> 0..100 (scaled into 0..255 for representation).

Usage Example

// QuantityUpdateSystem runs automatically as part of the ECS update group.
// Example: reading updated Quantity values from another system.
public partial class ExampleReadQuantitySystem : SystemBase
{
    protected override void OnUpdate()
    {
        Entities
            .WithAll<Quantity>()
            .ForEach((in Entity entity, in Quantity qty) =>
            {
                // qty.m_Fullness is a byte representing fullness percentage (0-255).
                // Convert to 0..100 range for display:
                int percent = Mathf.RoundToInt(qty.m_Fullness / 255f * 100f);
                // Do something with percent, e.g. update UI or debug log
                // Debug.Log($"Entity {entity} fullness: {percent}%");
            }).ScheduleParallel();
    }
}

Additional tips: - If you add custom QuantityObjectData or Resource types in mods, ensure your prefabs and storage components are consistent so QuantityUpdateSystem picks them up correctly. - Because the job uses many read-only lookups and buffers, ensure the corresponding components/buffers exist on entities you expect to be evaluated; otherwise the checks fall back gracefully (TryGetComponent / HasComponent / HasBuffer checks are used).