Game.Serialization.OwnedCreatureSystem
Assembly:
Namespace: Game.Serialization
Type: public class (CompilerGenerated)
Base: GameSystemBase
Summary:
A DOTS system that finds all Creature entities that have an Owner component and appends a corresponding OwnedCreature entry into the owning entity's dynamic buffer. The work of scanning chunks and writing into buffers is performed in a Burst-compiled IJobChunk (OwnedVehicleJob) using EntityTypeHandle, ComponentTypeHandle
Fields
-
private Unity.Entities.EntityQuery m_Query
Holds the EntityQuery used to find entities with both Creature and Owner components. Created in OnCreate and passed to JobChunk scheduling. -
private TypeHandle __TypeHandle
Container for cached type handles (EntityTypeHandle, ComponentTypeHandle(RO), BufferLookup (RW)). It is initialized in OnCreateForCompiler via __AssignHandles and used to populate the job's handle fields before scheduling.
Properties
- None (no public properties exposed by this system)
Constructors
public OwnedCreatureSystem()
Default constructor annotated with [Preserve]. Initializes the system instance; additional setup is performed in OnCreate/OnCreateForCompiler.
Methods
-
protected override void OnCreate()
Creates the EntityQuery for Creature + Owner (ReadOnly) and calls RequireForUpdate(m_Query) so the system only updates when matching entities exist. -
protected override void OnUpdate()
Builds an OwnedVehicleJob instance, fills its EntityTypeHandle / ComponentTypeHandle / BufferLookup fields via InternalCompilerInterface getters (using handles stored in __TypeHandle and the system's CheckedStateRef), then schedules the job with JobChunkExtensions.Schedule against m_Query and updates base.Dependency. -
private void __AssignQueries(ref SystemState state)
Compiler helper that currently constructs and disposes an EntityQueryBuilder(Allocator.Temp). Present to satisfy generated code paths; no useful runtime query assignment occurs here (actual query is created in OnCreate). -
protected override void OnCreateForCompiler()
Compiler-time initialization method that calls __AssignQueries and __TypeHandle.__AssignHandles to ensure type handles are assigned and ready for use by the generated scheduling code.
Nested types (important runtime behavior):
[BurstCompile] private struct OwnedVehicleJob : IJobChunk
- Fields:
EntityTypeHandle m_EntityType
ComponentTypeHandle<Owner> m_OwnerType
(ReadOnly)BufferLookup<OwnedCreature> m_OwnedCreatures
(RW)
- Execute: For each chunk, retrieves NativeArray
and NativeArray , iterates them, and for each entry checks if the owner entity has an OwnedCreature buffer (m_OwnedCreatures.HasBuffer(owner.m_Owner)). If the buffer exists, adds a new OwnedCreature containing the creature Entity into the owner's buffer. -
The IJobChunk wrapper calls the typed Execute to perform the chunked iteration. This job is Burst-compiled.
-
private struct TypeHandle
- Contains:
EntityTypeHandle __Unity_Entities_Entity_TypeHandle
ComponentTypeHandle<Owner> __Game_Common_Owner_RO_ComponentTypeHandle
BufferLookup<OwnedCreature> __Game_Creatures_OwnedCreature_RW_BufferLookup
- Method
__AssignHandles(ref SystemState state)
initializes the above handles from the provided SystemState (state.GetEntityTypeHandle(), state.GetComponentTypeHandle(isReadOnly:true), state.GetBufferLookup ()).
Usage Example
// Create an owner entity with an OwnedCreature buffer and a creature entity that references it.
// After the system runs, the owner's buffer will contain an OwnedCreature entry that references the creature.
Entity owner = entityManager.CreateEntity(typeof(OwnedCreature)); // has a dynamic buffer slot
DynamicBuffer<OwnedCreature> ownerBuffer = entityManager.GetBuffer<OwnedCreature>(owner); // initially empty
Entity creature = entityManager.CreateEntity(typeof(Creature), typeof(Owner));
entityManager.SetComponentData(creature, new Owner { m_Owner = owner });
// The OwnedCreatureSystem will run (if enabled) and append an OwnedCreature(creature) to the owner's buffer.
Notes and implementation details:
- The system uses a Burst-compiled IJobChunk to maximize performance when iterating over entity chunks.
- BufferLookup