Game.Serialization.AggregatedSystem
Assembly: Game (inferred)
Namespace: Game.Serialization
Type: class
Base: GameSystemBase
Summary:
AggregatedSystem is a Unity ECS system used to link "edge" entities to their parent "aggregate" entity. It iterates chunks that contain a DynamicBuffer
Fields
-
private EntityQuery m_Query
This query is configured in OnCreate to select entities that have a read-only AggregateElement buffer. The system calls RequireForUpdate(m_Query) so the system only updates when matching entities exist. -
private TypeHandle __TypeHandle
Container for the various ECS type handles used by the job (EntityTypeHandle, BufferTypeHandle, ComponentLookup ). The system assigns these handles from the SystemState (via __AssignHandles) to get thread-safe access inside the scheduled job.
Properties
- None
This system does not expose public properties. Internally it uses base.Dependency to store the job handle when scheduling.
Constructors
public AggregatedSystem()
Default public constructor. The system is annotated with [Preserve] on lifecycle methods, but the constructor itself performs no special initialization beyond base construction.
Methods
protected override void OnCreate()
Called when the system is created. Implementation:- Calls base.OnCreate().
- Builds m_Query = GetEntityQuery(ComponentType.ReadOnly
()). -
Calls RequireForUpdate(m_Query) to prevent updates when no matching entities exist. This sets up the runtime requirement for the system to run only when AggregateElement buffers exist.
-
protected override void OnUpdate()
Creates an AggregatedJob instance and populates its handles from the cached TypeHandle via InternalCompilerInterface.GetXXXHandle helpers, then schedules the job with JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency). The scheduled job updates Aggregated components on referenced edge entities to point to the aggregate entity. -
protected override void OnCreateForCompiler()
Called by generated/compiled code paths. It: - Calls base.OnCreateForCompiler().
-
Calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to prepare queries and type handles that the job will use.
-
[MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
Currently constructs and disposes an EntityQueryBuilder(Allocator.Temp) (placeholder in this compiled form). In other generated systems this method sets up explicit queries; here it exists for the compiler-generated initialization path. -
private struct TypeHandle.__AssignHandles(ref SystemState state)
(Inside the nested TypeHandle struct.) Assigns the concrete EntityTypeHandle, BufferTypeHandle(read-only) and ComponentLookup from the provided SystemState. These handles are later converted to job-capable handles in OnUpdate via InternalCompilerInterface helpers. -
private struct AggregatedJob : IJobChunk
Job struct used to process chunks: - Fields:
[ReadOnly] public EntityTypeHandle m_EntityType
— used to get the native entity array for the chunk.[ReadOnly] public BufferTypeHandle<AggregateElement> m_AggregateElementType
— used to access the DynamicBufferon each entity. public ComponentLookup<Aggregated> m_AggregatedData
— used to read/write the Aggregated component on referenced edge entities.
- Execute(in ArchetypeChunk chunk, ...) iterates the chunk's entities and for each AggregateElement in each DynamicBuffer:
- Reads the referenced edge entity (aggregateElement.m_Edge).
- If the edge entity has an Aggregated component (m_AggregatedData.HasComponent), reads it, sets its m_Aggregate field to the aggregate entity, and writes it back to m_AggregatedData[edge].
- The struct is annotated with [BurstCompile] to improve performance.
Notes on thread-safety and correctness:
- ComponentLookup
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Ensure this system runs only when entities with AggregateElement buffers exist
m_Query = GetEntityQuery(ComponentType.ReadOnly<AggregateElement>());
RequireForUpdate(m_Query);
}
[Preserve]
protected override void OnUpdate()
{
var jobData = new AggregatedJob
{
// Convert cached handles to job-capable handles via the InternalCompilerInterface helpers shown in the decompiled code:
m_EntityType = InternalCompilerInterface.GetEntityTypeHandle(ref __TypeHandle.__Unity_Entities_Entity_TypeHandle, ref base.CheckedStateRef),
m_AggregateElementType = InternalCompilerInterface.GetBufferTypeHandle(ref __TypeHandle.__Game_Net_AggregateElement_RO_BufferTypeHandle, ref base.CheckedStateRef),
m_AggregatedData = InternalCompilerInterface.GetComponentLookup(ref __TypeHandle.__Game_Net_Aggregated_RW_ComponentLookup, ref base.CheckedStateRef)
};
base.Dependency = JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency);
}
Additional notes for modders: - This is a compiler-generated system pattern typical for Unity's DOTS/ECS where a TypeHandle caches handles and an IJobChunk is Burst-compiled to operate over chunked data. - If you modify AggregateElement or Aggregated component definitions, ensure this system's assumptions (field names and expected semantics) remain consistent. - Be cautious when referencing entities from buffers and writing to components on those referenced entities — this can introduce race conditions if other jobs/systems operate on the same components concurrently. Use proper dependency handling or structural change synchronization when necessary.