Game.Serialization.DataMigration.QuantityObjectMissingSystem
Assembly:
Assembly-CSharp (game runtime)
Namespace:
Game.Serialization.DataMigration
Type:
public class QuantityObjectMissingSystem
Base:
GameSystemBase
Summary:
QuantityObjectMissingSystem is a data-migration system used during game load/deserialization to restore missing Quantity data on static world objects that should have quantity information (resource piles, etc.) for saves from before a specific version (Version.resourcePileFixes). The system finds entities that are Object + Static but that do not already have Quantity (and are not Plant or Building). For each such entity it checks the entity's PrefabRef; if that prefab has a QuantityObjectData component, the system adds Quantity and Updated components to the entity via a DeserializationBarrier EntityCommandBuffer (parallel writer). The work is done in a parallel IJobChunk (QuantityObjectMissingJob) and the job handle is registered with the DeserializationBarrier so changes happen safely with other deserialization producers.
Fields
-
private LoadGameSystem m_LoadGameSystem
Field referencing the LoadGameSystem for checking the current load context (version). The system only runs its migration logic when the saved game's version is older than Version.resourcePileFixes. -
private DeserializationBarrier m_DeserializationBarrier
Barrier system used to create an EntityCommandBuffer.ParallelWriter. Ensures commands produced by the parallel job are applied at the correct point in the deserialization pipeline and that dependencies are tracked. -
private EntityQuery m_Query
Query selecting candidate entities: has Object and Static, and excludes Quantity, Plant, and Building. Used to determine whether migration work is needed and to drive the JobChunk scheduling. -
private TypeHandle __TypeHandle
Struct that caches the EntityTypeHandle, the PrefabRef ComponentTypeHandle (read-only), and a ComponentLookup(read-only). __TypeHandle.__AssignHandles(ref SystemState) fills these handles from the current SystemState. -
private struct QuantityObjectMissingJob
(nested)
IJobChunk implementation that iterates chunks of entities matching the query. For each entity it: - reads the PrefabRef,
- checks that the prefab has a QuantityObjectData component (via ComponentLookup
.HasComponent), - if so, issues AddComponent(Quantity) and AddComponent(Updated) to the entity using the parallel EntityCommandBuffer.
Notes about the job:
- Uses EntityTypeHandle to get the entities in the chunk.
- Uses ComponentTypeHandle
Properties
- None (no public properties declared in this class)
Constructors
public QuantityObjectMissingSystem()
Default constructor. Marked with [Preserve] attribute in the source to avoid removing it during stripping/linking.
Methods
protected override void OnCreate()
Initializes the system:- Calls base.OnCreate().
- Acquires LoadGameSystem and DeserializationBarrier via World.GetOrCreateSystemManaged
(). -
Constructs the EntityQuery selecting Object + Static and excluding Quantity, Plant, Building. This prepares the system to only act on relevant entities during deserialization/migration.
-
protected override void OnUpdate()
Main runtime logic that runs every frame/update tick while loading/deserializing: - Checks if the save's version is older than Version.resourcePileFixes using m_LoadGameSystem.context.version.
- If so and the query isn't empty, schedules the QuantityObjectMissingJob using JobChunkExtensions.ScheduleParallel with the cached type handles and a parallel ECB writer from m_DeserializationBarrier.
-
Registers the returned JobHandle with m_DeserializationBarrier (AddJobHandleForProducer) and stores the handle in base.Dependency to ensure proper dependency chaining.
-
protected override void OnCreateForCompiler()
Compiler-time/IL post-processing helper used in generated/compiled systems: - Calls __AssignQueries(ref base.CheckedStateRef) (no-op here other than allocation pattern in source).
-
Calls __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to initialize type handles used by the job.
-
private void __AssignQueries(ref SystemState state)
Generated helper (in source it just creates and disposes an EntityQueryBuilder(Allocator.Temp)). Present to satisfy generated-system initialization patterns. -
private struct TypeHandle.__AssignHandles(ref SystemState state)
Initializes EntityTypeHandle, ComponentTypeHandle(read-only), and ComponentLookup (read-only) from the provided SystemState. Marked AggressiveInlining in source. -
QuantityObjectMissingJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
Core per-chunk execution method: - Retrieves entity array and PrefabRef array for the chunk.
- Loops entities and for each prefabRef checks the ComponentLookup
for the prefab entity. - If the prefab has QuantityObjectData, enqueues AddComponent(Quantity) and AddComponent(Updated) for that entity via the parallel ECB writer.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_LoadGameSystem = base.World.GetOrCreateSystemManaged<LoadGameSystem>();
m_DeserializationBarrier = base.World.GetOrCreateSystemManaged<DeserializationBarrier>();
m_Query = GetEntityQuery(
ComponentType.ReadOnly<Object>(),
ComponentType.ReadOnly<Static>(),
ComponentType.Exclude<Quantity>(),
ComponentType.Exclude<Plant>(),
ComponentType.Exclude<Building>()
);
}
Additional notes for modders: - This system is specifically a migration helper; you generally do not need to call it directly. It runs as part of the world/system update during load. - If you add or remove QuantityObjectData from prefabs in mods, be aware that this system checks prefab components (via ComponentLookup) and will add Quantity+Updated to matching world entities for old save compatibility. - The system schedules a parallel IJobChunk and uses an EntityCommandBuffer.ParallelWriter — ensure any additional systems that expect Quantity to exist either run after the DeserializationBarrier or account for the job dependency (the system already registers the job with the DeserializationBarrier).