Skip to content

Game.Citizens.HouseholdPetRemoveSystem

Assembly: Game
Namespace: Game.Citizens

Type: class (CompilerGenerated)

Base: GameSystemBase

Summary:
HouseholdPetRemoveSystem is an ECS system that runs when HouseholdPet entities have been marked for deletion (it queries HouseholdPet + Deleted and excludes Temp). On update it schedules a Burst-compiled IJobChunk (RemovePetJob) via a ModificationBarrier4 command buffer. The job: - Removes the removed pet's entity from its household's HouseholdAnimal buffer (and removes the HouseholdAnimal buffer component if it becomes empty). - If the pet had a CurrentTransport pointing to a Creature entity, and that creature exists in the Creature component lookup, the job marks that creature entity with a Deleted component (so it will be cleaned up by other removal logic).

The system uses ComponentTypeHandle/ComponentLookup/BufferLookup handles assigned in a private TypeHandle struct and uses RequireForUpdate to only run when relevant entities exist.

Fields

  • private EntityQuery m_HouseholdPetQuery
    This EntityQuery selects entities with HouseholdPet and Deleted components, excluding Temp. It's used to schedule the RemovePetJob only when there are pets to remove.

  • private ModificationBarrier4 m_ModificationBarrier
    A modification barrier system used to create an EntityCommandBuffer for safe structural changes from the scheduled job. The system adds the job handle to this barrier so commands are applied correctly.

  • private TypeHandle __TypeHandle
    Internal struct instance that stores EntityTypeHandle, ComponentTypeHandles, ComponentLookup and BufferLookup used by scheduled jobs. These handles are assigned from the SystemState in OnCreateForCompiler.


Properties

  • None (this system exposes no public properties).
    This system only uses internal/private handles and fields; changes are performed via the command buffer created from m_ModificationBarrier.

Constructors

  • public HouseholdPetRemoveSystem()
    Default constructor (marked with [Preserve]). Nothing special is done in the constructor itself; initialization happens in OnCreate and OnCreateForCompiler.

Methods

  • protected override void OnCreate() : System.Void
    Creates/gets the ModificationBarrier4 system and constructs the m_HouseholdPetQuery: GetEntityQuery(ComponentType.ReadOnly(), ComponentType.ReadOnly(), ComponentType.Exclude);
    Calls RequireForUpdate(m_HouseholdPetQuery) so the system only updates when relevant entities exist.

  • protected override void OnUpdate() : System.Void
    Builds and schedules the Burst-compiled RemovePetJob using the assigned type handles and a command buffer from m_ModificationBarrier. Adds the resulting JobHandle to the modification barrier (AddJobHandleForProducer) and stores the handle in base.Dependency.

  • protected override void OnCreateForCompiler() : System.Void
    Called by generated code to assign internal queries and type handles for use by the compiler-generated job scheduling. It calls __AssignQueries and __TypeHandle.__AssignHandles.

  • private void __AssignQueries(ref SystemState state) : System.Void
    Generated stub for query assignment (currently creates and disposes an EntityQueryBuilder). Present for compiler compatibility.

Nested types / job methods (not public on the system but important to know):

  • private struct RemovePetJob : IJobChunk (BurstCompile)
  • Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex, bool useEnabledMask, in v128 chunkEnabledMask) : System.Void
    For each entity in the chunk:
    • Reads HouseholdPet and removes the corresponding HouseholdAnimal entry from the target household's DynamicBuffer. If the buffer becomes empty, issues RemoveComponent on that household via the command buffer.
    • Reads CurrentTransport and, if the referenced transport creature exists in the Creature ComponentLookup, issues AddComponent on that creature entity via the command buffer.
  • The job uses:

    • EntityTypeHandle for reading entity IDs,
    • ComponentTypeHandle and ComponentTypeHandle (read-only),
    • ComponentLookup (read-only),
    • BufferLookup (mutable access to household buffers),
    • EntityCommandBuffer for structural changes.
  • private struct TypeHandle

  • public void __AssignHandles(ref SystemState state)
    Assigns all EntityTypeHandle / ComponentTypeHandles / ComponentLookup / BufferLookup fields from the state (state.GetEntityTypeHandle(), state.GetComponentTypeHandle<...>(), state.GetComponentLookup<...>(), state.GetBufferLookup<...>()).

Usage Example

This system runs automatically as part of the game's ECS when HouseholdPet entities are marked with Deleted. Example of how an external system or authoring code might mark a pet for removal — the HouseholdPetRemoveSystem will then process it on the next update:

// Example: mark a pet for deletion so HouseholdPetRemoveSystem will clean up household buffers
// (This code would run from some other system or game logic)
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity petEntity = /* obtain the pet entity */;
em.AddComponentData(petEntity, new Deleted()); // mark the pet for removal

// After this, on the next frame the HouseholdPetRemoveSystem will:
// - remove the pet from the household's HouseholdAnimal buffer (and remove buffer component if empty)
// - if the pet was carrying/transporting a Creature via CurrentTransport, mark that Creature entity with Deleted

Notes: - The actual structural changes are performed via a command buffer created from ModificationBarrier4 inside the scheduled job; direct structural changes from the job are not performed. - The job is Burst-compiled and scheduled with JobChunkExtensions.Schedule for performance.