Game.PetSystem
Assembly: Assembly-CSharp
Namespace: Game.Serialization
Type: class
Base: GameSystemBase
Summary:
PetSystem is a compiler-generated ECS system that ensures each pet entity's Pet component points back to its household pet Entity. It scans entities that carry a CurrentTransport component (and are tagged with HouseholdPet) and, for each household-pet mapping, looks up the corresponding Pet component on the transported creature entity and writes the household pet Entity into the Pet.m_HouseholdPet field. The system uses a Burst-compiled IJobChunk (PetJob) and DOTS type handles / component lookups for efficient, parallel execution.
Fields
-
private EntityQuery m_Query
Holds the entity query used to select entities with CurrentTransport and HouseholdPet components. The system calls RequireForUpdate(m_Query) in OnCreate so the system only runs when matching entities exist. -
private TypeHandle __TypeHandle
A compiler-generated struct that stores the various EntityTypeHandle, ComponentTypeHandle(read-only) and ComponentLookup (read-write) used by the job. Its __AssignHandles method is called in OnCreateForCompiler to initialize these handles from the provided SystemState. -
(nested)
private struct PetJob
Burst-compiled IJobChunk that performs the main work. See Methods section for field-level details of the job. -
(nested)
private struct TypeHandle
Compiler-generated helper struct containing: EntityTypeHandle __Unity_Entities_Entity_TypeHandle
(read-only)ComponentTypeHandle<CurrentTransport> __Game_Citizens_CurrentTransport_RO_ComponentTypeHandle
(read-only)ComponentLookup<Pet> __Game_Creatures_Pet_RW_ComponentLookup
(read-write)
Properties
- None (the system exposes no public properties).
Constructors
public PetSystem()
Default parameterless constructor. Marked with [Preserve] in the source, as this is a compiler-generated system; no additional runtime initialization beyond base constructor.
Methods
-
protected override void OnCreate()
Called when the system is created. Initializes m_Query to select entities with ComponentType.ReadOnly() and ComponentType.ReadOnly (), and calls RequireForUpdate(m_Query) so the system only updates when such entities exist. -
protected override void OnUpdate()
Creates and populates a PetJob instance, filling its handles by obtaining them through InternalCompilerInterface.GetEntityTypeHandle / GetComponentTypeHandle / GetComponentLookup with references to the compiled __TypeHandle and the system state. Schedules the job with JobChunkExtensions.Schedule(jobData, m_Query, base.Dependency) and assigns the returned JobHandle to base.Dependency. -
protected override void OnCreateForCompiler()
Compiler helper called to assign any queries and initialize type handles at compile-time. Calls __AssignQueries and __TypeHandle.__AssignHandles with the system state. -
private void __AssignQueries(ref SystemState state)
Compiler-generated query assignment helper; current implementation constructs (and immediately disposes) an empty EntityQueryBuilder(Allocator.Temp). Present for compatibility with generated code patterns. -
(nested) PetJob.Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) : System.Void
The job iterates the chunk's arrays: - Reads the Entity array (household pet entities) via m_EntityType.
- Reads the CurrentTransport array (read-only) via m_CurrentTransportType.
- For each entry, it checks whether the transported entity (currentTransport.m_CurrentTransport) has a Pet component via m_PetData.HasComponent(...).
-
If the transported entity has a Pet component, it reads that Pet, sets Pet.m_HouseholdPet = householdPet, and writes the Pet back via the ComponentLookup
. This job is Burst-compiled and scheduled as an IJobChunk. -
(nested) TypeHandle.__AssignHandles(ref SystemState state)
Initializes the internal EntityTypeHandle and ComponentTypeHandle/ComponentLookup fields by calling: - state.GetEntityTypeHandle()
- state.GetComponentTypeHandle
(isReadOnly: true) - state.GetComponentLookup
() This method is [MethodImpl(MethodImplOptions.AggressiveInlining)] in the original code.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// This matches the implementation in PetSystem: select entities with CurrentTransport and HouseholdPet
m_Query = GetEntityQuery(ComponentType.ReadOnly<CurrentTransport>(), ComponentType.ReadOnly<HouseholdPet>());
RequireForUpdate(m_Query);
}
Notes and implementation remarks:
- The system is compiler-generated to work with Unity DOTS (Entities package). It uses EntityTypeHandle, ComponentTypeHandle