Skip to content

Game.GroupCreatureSystem

Assembly:
Namespace: Game.Serialization

Type: class

Base: GameSystemBase

Summary:
A compiler-generated ECS system that collects all entities with a GroupMember component and appends a GroupCreature entry to the leader's GroupCreature dynamic buffer for each member. The work is performed in a Burst-compiled IJobChunk (GroupCreatureJob) that reads Entity and GroupMember components and uses a BufferLookup to add GroupCreature buffers to leader entities. This system requires an EntityQuery for GroupMember and uses generated type-handle plumbing to obtain the required Component/Entity/Buffer handles in a safe, high-performance way.


Fields

  • private EntityQuery m_Query
    Used to select entities that have a GroupMember component. The query is created in OnCreate and passed to JobChunkExtensions.Schedule in OnUpdate.

  • private TypeHandle __TypeHandle
    A compiler-generated container for the various type handles the job requires:

  • EntityTypeHandle
  • ComponentTypeHandle (read-only)
  • BufferLookup (read/write)
    The TypeHandle struct provides an __AssignHandles method to populate these handles from a SystemState.

Properties

  • (No public properties)
    This system exposes no public properties. All runtime handles and state are kept internal/private and wired via the generated TypeHandle and job-data.

Constructors

  • public GroupCreatureSystem()
    Default, preserved constructor. No special initialization beyond what GameSystemBase does; actual setup happens in OnCreate/OnCreateForCompiler.

Methods

  • protected override void OnCreate()
    Initializes the EntityQuery that selects entities with GroupMember and registers the query as a requirement for the system to run (RequireForUpdate). This ensures the system only updates when matching entities exist.

  • protected override void OnUpdate()
    Builds an instance of the Burst-compiled GroupCreatureJob, populating its EntityTypeHandle, ComponentTypeHandle, and BufferLookup using InternalCompilerInterface and the prepopulated __TypeHandle. Schedules the job via JobChunkExtensions.Schedule against m_Query, chaining it to base.Dependency.

  • private void __AssignQueries(ref SystemState state)
    Compiler-generated helper used to create/assign any queries needed at compile-time. In this implementation it constructs and immediately disposes an EntityQueryBuilder; the actual query used by the system is created in OnCreate.

  • protected override void OnCreateForCompiler()
    Compiler helper called during system creation. Calls __AssignQueries and instructs the TypeHandle to assign its handles from the SystemState (via __AssignHandles). This bridges the generated handle plumbing and the runtime state.

  • GroupCreatureJob (nested, Burst-compiled, implements IJobChunk)

  • Fields:
    • EntityTypeHandle m_EntityType (ReadOnly)
    • ComponentTypeHandle<GroupMember> m_GroupMemberType (ReadOnly)
    • BufferLookup<GroupCreature> m_GroupCreatures (RW)
  • Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask)
    • Fetches the chunk's Entity array and GroupMember component array.
    • Iterates each element, gets the creature Entity and the GroupMember value, then appends a new GroupCreature(creature) to the leader entity's GroupCreature buffer using m_GroupCreatures[groupMember.m_Leader].Add(...).
    • The job performs per-chunk iteration in a data-oriented manner and is Burst-compiled for performance.
  • Implements the IJobChunk.Execute wrapper to call the strongly-typed Execute above.

  • TypeHandle.__AssignHandles(ref SystemState state)
    Populates the stored EntityTypeHandle, ComponentTypeHandle (read-only), and BufferLookup from the provided SystemState. Marked AggressiveInlining for performance.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Create a query that matches entities with GroupMember
    m_Query = GetEntityQuery(ComponentType.ReadOnly<GroupMember>());
    // Only run this system when there are GroupMember entities
    RequireForUpdate(m_Query);
}

[Preserve]
protected override void OnUpdate()
{
    // Build the job data using the generated TypeHandle values (this is compiler-generated in the system)
    GroupCreatureJob jobData = new GroupCreatureJob
    {
        m_EntityType = InternalCompilerInterface.GetEntityTypeHandle(ref __TypeHandle.__Unity_Entities_Entity_TypeHandle, ref base.CheckedStateRef),
        m_GroupMemberType = InternalCompilerInterface.GetComponentTypeHandle(ref __TypeHandle.__Game_Creatures_GroupMember_RO_ComponentTypeHandle, ref base.CheckedStateRef),
        m_GroupCreatures = InternalCompilerInterface.GetBufferLookup(ref __TypeHandle.__Game_Creatures_GroupCreature_RW_BufferLookup, ref base.CheckedStateRef)
    };

    // Schedule the chunk job to populate leader buffers with GroupCreature entries for each member
    base.Dependency = JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency);
}

Additional notes: - This is a compiler-generated system pattern typical for DOTS/ECS code that uses Enableable/Generated type-handle plumbing. The explicit InternalCompilerInterface calls and __TypeHandle helpers are part of that generated scaffolding. - The GroupCreatureJob uses a BufferLookup indexed by the leader Entity (groupMember.m_Leader). Ensure leaders have the GroupCreature buffer component on them before this job runs, otherwise the BufferLookup access will fail.