Game.ResetUpdateGroupSizesSystem
Assembly: Assembly-CSharp
Namespace: Game.Serialization
Type: class
Base: GameSystemBase
Summary:
ResetUpdateGroupSizesSystem is a small runtime system that recomputes the sizes (entity counts) of update groups by iterating over chunks that have the UpdateFrame shared component. It schedules a Burst-compiled IJob (ResetUpdateGroupSizesJob) that aggregates chunk counts into an UpdateGroupSystem.UpdateGroupSizes structure (obtained from the UpdateGroupSystem). The system updates its internal UpdateGroupTypes helper and uses an EntityQuery to gather chunks asynchronously, combining job dependencies correctly and disposing temporary lists after scheduling.
Fields
-
private UpdateGroupSystem m_UpdateGroupSystem
Reference to the game's UpdateGroupSystem. Used to retrieve the UpdateGroupSizes instance that will be populated by the scheduled job. -
private UpdateGroupSystem.UpdateGroupTypes m_UpdateGroupTypes
Helper structure that caches type handles or other information required to read update-group-related data from chunks. Updated each frame before scheduling the job. -
private EntityQuery m_UpdateFrameQuery
EntityQuery used to select chunks that contain the UpdateFrame shared component. These chunks are converted into an ArchetypeChunk list and passed to the job. -
private TypeHandle __TypeHandle
Holds component/ shared-component type handles (here, the SharedComponentTypeHandle) used by jobs. Populated via __AssignHandles when the system is created for the compiler. -
private struct ResetUpdateGroupSizesJob
(nested, private)
Burst-compiled IJob that does the actual work. Fields: NativeList<ArchetypeChunk> m_Chunks
(ReadOnly) — list of chunks to process.SharedComponentTypeHandle<UpdateFrame> m_UpdateFrameType
(ReadOnly) — shared component handle for reading UpdateFrame from chunks.UpdateGroupSystem.UpdateGroupTypes m_UpdateGroupTypes
(ReadOnly) — group types helper to derive per-chunk arrays.UpdateGroupSystem.UpdateGroupSizes m_UpdateGroupSizes
— target structure to accumulate per-frame entity counts.
Behavior: Clears the UpdateGroupSizes, then iterates chunks; for each chunk it retrieves a NativeArray
private struct TypeHandle
(nested, private)
Contains a SharedComponentTypeHandlenamed __Game_Simulation_UpdateFrame_SharedComponentTypeHandle and a method to assign handles from a SystemState.
Properties
- This system exposes no public properties.
Constructors
public ResetUpdateGroupSizesSystem()
Default parameterless constructor. Marked with [Preserve] on the system's lifecycle methods to keep them in builds that strip unused code.
Methods
-
[Preserve] protected override void OnCreate()
Initializes the system: obtains or creates the UpdateGroupSystem from the World, builds the EntityQuery for UpdateFrame, and constructs the UpdateGroupTypes helper (passing this system as context). -
[Preserve] protected override void OnUpdate()
Main update path: - Converts m_UpdateFrameQuery into a NativeList
asynchronously (ToArchetypeChunkListAsync), receiving an outJobHandle. - Calls m_UpdateGroupTypes.Update(this) to refresh any type handles cached in the helper.
- Constructs and schedules ResetUpdateGroupSizesJob (Burst compiled), passing chunks, the SharedComponentTypeHandle
obtained via InternalCompilerInterface.GetSharedComponentTypeHandle, the update-group types, and the UpdateGroupSizes from m_UpdateGroupSystem. - Combines dependencies using JobHandle.CombineDependencies(base.Dependency, outJobHandle).
- Disposes the temporary chunks list with chunks.Dispose(jobHandle) to ensure disposal runs after the scheduled job.
- Stores the scheduled job handle back to base.Dependency.
This method ensures the reset/aggregation runs fully asynchronously and that temporary allocations are disposed after the job completes.
-
private void __AssignQueries(ref SystemState state)
Compiler-generated helper that can create/assign entity queries. In this file it runs an EntityQueryBuilder and disposes it — used by OnCreateForCompiler to ensure queries are created when compiling/reflection requires it. -
[MethodImpl(MethodImplOptions.AggressiveInlining)] public void __AssignHandles(ref SystemState state)
(in nested TypeHandle)
Assigns the SharedComponentTypeHandlefrom the provided SystemState (state.GetSharedComponentTypeHandle ()). -
protected override void OnCreateForCompiler()
Compiler helper invoked for code-generation/IL post-processing: calls __AssignQueries and assigns the type handles by calling __TypeHandle.__AssignHandles(ref base.CheckedStateRef).
Usage Example
// The system runs automatically as part of the World update loop.
// Example: reading the computed sizes from another system.
protected override void OnUpdate()
{
// Ensure ResetUpdateGroupSizesSystem has run in the same frame / before reading.
var updateGroupSystem = World.GetExistingSystemManaged<UpdateGroupSystem>();
if (updateGroupSystem != null)
{
// GetUpdateGroupSizes returns the UpdateGroupSizes structure populated
// by ResetUpdateGroupSizesSystem's job (after its scheduled job completes).
var sizes = updateGroupSystem.GetUpdateGroupSizes();
// Example: read size for a specific update-frame index (if valid)
uint frameIndex = 0; // example index
if (frameIndex < sizes.Length)
{
int count = sizes[(int)frameIndex];
// use count...
}
}
}
Notes / Tips:
- The aggregation is done in a Burst-compiled IJob and leverages shared component indices to bucket chunk counts into frame slots; this is efficient for large entity sets.
- The system carefully combines dependencies and disposes the temporary chunk list with a dependent job handle to avoid race conditions or leaks.
- Because the job reads a SharedComponentTypeHandle