Skip to content

Game.RemovedSystem

Assembly: Game (inferred)
Namespace: Game.Simulation

Type: RemovedSystem

Base: GameSystemBase

Summary:
RemovedSystem is an ECS system responsible for cleaning up state when entities (buildings, workplaces, companies, renters, etc.) are removed or otherwise marked Deleted. It schedules several Burst-compiled IJobChunk jobs to: - Remove or update components on related entities (e.g., remove PropertyRenter, Worker, TravelPurpose). - Update renter buffers on properties and remove renter references for deleted renters. - Clear or remove company-related notifications/icons via IconCommandBuffer. - Update building flags and notifications (e.g., clear HighRentWarning when appropriate).

The system uses an internal TypeHandle to cache Entity/Component/Buffer handles for scheduling jobs, and relies on ModificationBarrier5 and IconCommandSystem to issue thread-safe changes (EntityCommandBuffer and IconCommandBuffer). Jobs are scheduled in parallel where possible and combined into the system Dependency.


Fields

  • private EntityQuery m_DeletedBuildings
    Tracks entities that have a Renter buffer and are marked Deleted (and not Temp). Used to find properties whose renters need cleanup.

  • private EntityQuery m_DeletedWorkplaces
    Tracks entities that have Employee buffers and are marked Deleted (and not Temp). Used to clean up workplace-related components on employees.

  • private EntityQuery m_DeletedCompanies
    Tracks CompanyNotifications components on entities marked Deleted. Used to remove icons/notifications for deleted companies.

  • private EntityQuery m_NeedUpdateRenterQuery
    Query for entities that need renter updates (Event + RentersUpdated). Used to process renter lists and building notifications.

  • private EntityQuery m_BuildingParameterQuery
    Query to access BuildingConfigurationData singleton (used for notification prefabs, etc).

  • private EntityQuery m_CompanyNotificationParameterQuery
    Query to access CompanyNotificationParameterData singleton (used for company notification prefabs).

  • private IconCommandSystem m_IconCommandSystem
    Reference to the IconCommandSystem used to create IconCommandBuffer instances for icon/notification changes.

  • private ModificationBarrier5 m_ModificationBarrier
    Barrier system used to create EntityCommandBuffer writers for structural/component changes from jobs.

  • private TypeHandle __TypeHandle
    Internal struct instance that holds the Entity/Component/Buffer handles used by the jobs. Populated via __AssignHandles.

Notes: - The system relies on these queries and barriers to safely perform multi-threaded removals and component updates. - Many fields are used to create read-only or read-write Component/Buffer handles inside jobs; see the TypeHandle struct for the specific handles.


Properties

  • None (no public properties exposed by this system)

Constructors

  • public RemovedSystem()
    Default constructor. The system is preserved and set up by the DOTS world; actual initialization of queries and barriers happens in OnCreate.

Methods

  • protected override void OnCreate()
    Performs initialization:
  • Acquires ModificationBarrier5 and IconCommandSystem instances from the world.
  • Creates the EntityQuery instances used later to detect deleted buildings, workplaces, companies, and renter update events.
  • Prepares queries for parameter/singleton data (BuildingConfigurationData, CompanyNotificationParameterData).

Notes for modders: - If you introduce new types that require cleanup on deletion, you will typically need to add appropriate queries or extend the existing jobs to handle them. - The method is marked [Preserve] in the original code to avoid stripping.

  • protected override void OnUpdate()
    Main scheduling method. It:
  • Checks each EntityQuery (deleted buildings, workplaces, companies, renter updates).
  • Schedules the corresponding Burst IJobChunk job(s) where required:
    • RemovedPropertyJob (parallel) for deleted buildings: removes PropertyRenter, handles lodging/tourist households, marks renter entities Deleted.
    • RemovedWorkplaceJob (parallel) for deleted workplaces: removes FreeWorkplaces on workplace entities, removes TravelPurpose/Worker components from employees heading to or at work.
    • RemovedCompanyJob (parallel) for deleted companies: removes company-related icons using IconCommandBuffer and CompanyNotificationParameterData.
    • RentersUpdateJob (non-parallel JobChunk.Schedule): cleans up renter buffers for properties when renters move away or are deleted, removes incorrect entries, and removes high-rent notifications when appropriate.
  • Registers job handles with the ModificationBarrier5 and IconCommandSystem as producers to ensure safe playback of command buffers.
  • Combines and assigns base.Dependency for job chaining.

Important details: - The system takes care to only schedule jobs if relevant queries are non-empty, and uses parameter query singletons for notification prefabs. - RemovedPropertyJob and RemovedWorkplaceJob use EntityCommandBuffer.ParallelWriter to record structural/component changes safely from worker threads. - RemovedCompanyJob and RentersUpdateJob use IconCommandBuffer to add/remove UI icons/notifications.

  • protected override void OnCreateForCompiler()
    Internal setup for code generation/IL-compatibility: calls __AssignQueries and __AssignHandles. Ensures the TypeHandle has its internal handles assigned.

  • private void __AssignQueries(ref SystemState state)
    Internal helper used by OnCreateForCompiler; currently a placeholder that instantiates an EntityQueryBuilder and disposes it. Present for compiler-compatible initialization.

  • private struct TypeHandle
    Holds all EntityTypeHandle, BufferLookup/BufferTypeHandle, ComponentLookup and ComponentTypeHandle instances used by the jobs. It contains an __AssignHandles(ref SystemState state) method that populates these handles via state.Get* calls. This struct is critical to pass thread-safe handles into Burst jobs.

  • Inner job structs (all Burst-compiled):

  • RemovedPropertyJob : IJobChunk
    • Reads entity list and Renter buffers.
    • For each renter listed on a removed property:
    • Removes PropertyRenter component from renter (if present).
    • If renter is a lodging provider with its own renter buffer, it iterates renters of that provider and clears TouristHousehold.m_Hotel for tourist households, recording the change via SetComponent.
    • Adds Deleted component to the renter entity.
  • RemovedWorkplaceJob : IJobChunk
    • Removes FreeWorkplaces from workplace entities (structural removal).
    • Iterates Employee buffers and for each employee's worker entity:
    • Removes TravelPurpose if purpose is GoingToWork or Working.
    • Removes Worker component if present.
  • RemovedCompanyJob : IJobChunk
    • Iterates CompanyNotifications on deleted companies and removes associated icon entities using IconCommandBuffer with prefabs from CompanyNotificationParameterData.
  • RentersUpdateJob : IJobChunk
    • For each RentersUpdated event:
    • Gets the renter buffer for the property.
    • Removes entries whose renter entity is MovingAway or Deleted.
    • If the property is not a homeless shelter (checked via BuildingUtils.IsHomelessShelterBuilding), removes renter entries whose PropertyRenter no longer points to the property.
    • If Building has HighRentWarning flag but buffer is empty, removes the high rent notification via IconCommandBuffer and clears the flag on the Building component.

Notes: - All job Execute methods implement IJobChunk.Execute and call into their implementation; these are Burst compiled for performance. - When modifying component data inside jobs, EntityCommandBuffer (parallel writer) or IconCommandBuffer are used so changes can be safely applied after the job finishes.


Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Example: Acquire barriers and queries (the real system does more)
    m_ModificationBarrier = base.World.GetOrCreateSystemManaged<ModificationBarrier5>();
    m_IconCommandSystem = base.World.GetOrCreateSystemManaged<IconCommandSystem>();
    m_DeletedBuildings = GetEntityQuery(ComponentType.ReadOnly<Renter>(), ComponentType.ReadOnly<Deleted>(), ComponentType.Exclude<Temp>());
    // Other queries and initialization follow...
}

Additional guidance for modders: - If you add new entity relationships that must be cleaned up when an entity is deleted (e.g., a new buffer or component referencing other entities), update RemovedSystem to handle them so ghost references and UI artifacts are not left behind. - Use ModificationBarrier/EntityCommandBuffer.ParallelWriter for structural or component removals performed from jobs. - Use IconCommandSystem/IconCommandBuffer when adding/removing UI icons or notifications from parallel jobs. - Be cautious modifying component layout or flags: ensure changes are consistent with other systems that may read/write the same components, and respect job dependencies by registering producers with barriers.