Game.Serialization.AvailabilitySystem
Assembly: Assembly-CSharp (inferred; game runtime assembly)
Namespace: Game.Serialization
Type: class
Base: GameSystemBase
Summary:
AvailabilitySystem is a compiler-generated Unity DOTS system used to ensure that entities which have a ResourceAvailability dynamic buffer always contain at least 34 entries. It schedules a Burst-compiled IJobChunk (AvailabilityJob) that iterates chunks containing the ResourceAvailability buffer and grows each entity's DynamicBuffer
Fields
-
private EntityQuery m_Query
Used to select entities that have a ResourceAvailability buffer. The query is created in OnCreate and passed to scheduling so that the job processes only matching chunks. The system also calls RequireForUpdate(m_Query) so it runs only when matching entities exist. -
private TypeHandle __TypeHandle
A compiler-generated struct instance that holds cached BufferTypeHandle(named __Game_Net_ResourceAvailability_RW_BufferTypeHandle inside the TypeHandle type). The system uses this to obtain the correct BufferTypeHandle for scheduling the job.
Properties
- This system does not expose any public properties.
Constructors
public AvailabilitySystem()
Default constructor marked with [Preserve] to prevent stripping. No custom construction logic beyond what GameSystemBase provides.
Methods
-
[Preserve] protected override void OnCreate()
Creates the entity query for ResourceAvailability and calls RequireForUpdate(m_Query) so the system only updates when there are matching entities. Calls base.OnCreate(). -
[Preserve] protected override void OnUpdate()
Creates and populates the AvailabilityJob (setting m_AvailabilityType using the cached type handle via InternalCompilerInterface.GetBufferTypeHandle) and schedules it in parallel across the m_Query using JobChunkExtensions.ScheduleParallel. The returned JobHandle is assigned to base.Dependency so it integrates into the system dependency chain. -
private void __AssignQueries(ref SystemState state)
(inlined)
Compiler-generated helper that currently creates and immediately disposes an empty EntityQueryBuilder(Allocator.Temp). Present for compiler/DOTS glue; no effective query logic is added here. -
protected override void OnCreateForCompiler()
Compiler glue called during system creation: calls __AssignQueries and __TypeHandle.__AssignHandles to initialize cached type handles for the DOTS runtime. Also calls base.OnCreateForCompiler(). -
[MethodImpl(MethodImplOptions.AggressiveInlining)]
inside TypeHandle:public void __AssignHandles(ref SystemState state)
Assigns the BufferTypeHandleinto the __Game_Net_ResourceAvailability_RW_BufferTypeHandle field of the TypeHandle struct using state.GetBufferTypeHandle (). -
AvailabilityJob (private nested struct, [BurstCompile], implements IJobChunk)
- Field:
public BufferTypeHandle<ResourceAvailability> m_AvailabilityType
— buffer handle used to access DynamicBufferon chunks. - Method:
public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
— for each entity in the chunk, obtains the DynamicBufferand while its Length < 34, adds new ResourceAvailability entries initialized with m_Availability = 0f. The struct explicitly implements IJobChunk.Execute by calling its own Execute method (standard pattern).
Notes: - The job is marked with [BurstCompile] for Burst optimization. - The code relies on Game.Net.ResourceAvailability (buffer element struct) which is expected to contain a float field m_Availability. - Methods and constructor are attributed with [Preserve] to avoid being stripped by Unity's managed code stripping.
Usage Example
// Ensure an entity has a ResourceAvailability buffer (so AvailabilitySystem will run on it)
var entity = entityManager.CreateEntity();
entityManager.AddBuffer<Game.Net.ResourceAvailability>(entity);
// After the AvailabilitySystem updates (scheduled by the world), the buffer will be
// expanded so its Length is at least 34, with any new entries having m_Availability = 0f.
If you need a snippet showing the system's internal job scheduling (mirroring OnUpdate):
// Pseudo-mirroring of the system's scheduling inside its OnUpdate:
var jobData = new AvailabilityJob {
m_AvailabilityType = InternalCompilerInterface.GetBufferTypeHandle(ref __TypeHandle.__Game_Net_ResourceAvailability_RW_BufferTypeHandle, ref CheckedStateRef)
};
Dependency = JobChunkExtensions.ScheduleParallel(jobData, m_Query, Dependency);
If you want, I can also: - Document the ResourceAvailability buffer element (if you provide its type), or - Produce a small example mod showing how to create entities with the buffer and observe the system's effect.