Skip to content

Game.SubmergeSystem

Assembly: Assembly-CSharp.dll
Namespace: Game.Events

Type: class

Base: GameSystemBase

Summary:
SubmergeSystem processes Submerge components (events that indicate an entity was submerged) and updates the world state accordingly. It aggregates Submerge entries per target entity (keeping the highest reported flood depth), creates or updates a Flooded component on the target entity, appends the target to the triggering Event's TargetElement buffer (if present), and emits AddEventJournalData entities for buildings when an event changes their flooded state. Work is performed inside a Burst-compiled IJob (SubmergeJob) using chunk iteration, NativeParallelHashMap for aggregation, and an EntityCommandBuffer produced by a ModificationBarrier4 to safely perform structural changes from a job. The system schedules the job asynchronously and uses ComponentLookup/BufferLookup handles assigned each compiler update.


Fields

  • private ModificationBarrier4 m_ModificationBarrier
    This modification barrier/system is used to create an EntityCommandBuffer for safely applying structural changes (adding Flooded components, creating journal entities) from the Burst IJob.

  • private EntityQuery m_FaceWeatherQuery
    EntityQuery used to collect all entities that have a Submerge component and an Event. It is required for update (RequireForUpdate) so the system only runs when Submerge components are present.

  • private EntityArchetype m_JournalDataArchetype
    Archetype created at OnCreate for journal entities that carry AddEventJournalData and Event components. Used when a building is affected to produce an AddEventJournalData entity for tracking.

  • private TypeHandle __TypeHandle
    Holds the cached ComponentTypeHandle/ComponentLookup/BufferLookup instances for the Submerge, PrefabRef, Building, Flooded and TargetElement types. These are assigned via __AssignHandles and used to obtain the runtime handles passed into the job.

Properties

This type does not declare any public properties.

Constructors

  • public SubmergeSystem()
    Default constructor. Calls base constructor and is annotated with Preserve in the compiled assembly. No additional initialization is performed here; runtime setup occurs in OnCreate.

Methods

  • protected override void OnCreate()
    Initializes members used by the system: retrieves/creates the ModificationBarrier4, constructs the EntityQuery (m_FaceWeatherQuery) to select Submerge+Event entities, creates the m_JournalDataArchetype (AddEventJournalData + Event), and calls RequireForUpdate(m_FaceWeatherQuery) so the system only runs when relevant Submerge entities exist.

  • protected override void OnUpdate()
    Main update logic: builds an async ArchetypeChunk list from m_FaceWeatherQuery, constructs and schedules the Burst-compiled SubmergeJob with the chunk list, component type/lookups, a command buffer from the modification barrier, and the journal archetype. The chunk list is disposed with the job handle; the modification barrier is given the producer job handle and the system base.Dependency is set to the scheduled job handle.

  • private void __AssignQueries(ref SystemState state)
    Compiler helper for query initialization. In this build it creates and disposes an empty EntityQueryBuilder (placeholder used by generated code patterns). Called from OnCreateForCompiler.

  • protected override void OnCreateForCompiler()
    Compiler-time initialization helper that calls __AssignQueries and assigns the component handles by calling __TypeHandle.__AssignHandles(ref base.CheckedStateRef). This method helps ensure the TypeHandle fields are set up for the runtime environment produced by the generated code.

Nested / job logic (summary): - SubmergeJob (BurstCompile, implements IJob) — iterates provided chunks of Submerge components, aggregates the maximum Flooded depth per target Entity using NativeParallelHashMap, checks PrefabRef and existing Flooded state, updates or adds Flooded components via the provided EntityCommandBuffer, adds affected entities to the Event's TargetElement buffer (using CollectionUtils.TryAddUniqueValue), and when a building's Flooded event changes it creates an AddEventJournalData entity using the provided m_JournalDataArchetype. SubmergeJob.AddJournalData is a helper that creates journal entities only for building targets.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_ModificationBarrier = base.World.GetOrCreateSystemManaged<ModificationBarrier4>();
    m_FaceWeatherQuery = GetEntityQuery(ComponentType.ReadOnly<Submerge>(), ComponentType.ReadOnly<Game.Common.Event>());
    m_JournalDataArchetype = base.EntityManager.CreateArchetype(ComponentType.ReadWrite<AddEventJournalData>(), ComponentType.ReadWrite<Game.Common.Event>());
    RequireForUpdate(m_FaceWeatherQuery);
}

Notes and tips for modders: - The system relies on the presence of PrefabRef on targets to validate that a Submerge target is a valid game object; entities missing PrefabRef will be ignored. - Aggregation keeps the maximum depth per target across all Submerge components processed in a frame — this prevents multiple smaller submerge reports from overwriting a larger one. - Structural changes (adding Flooded component or creating journal entities) are performed through the modification barrier's command buffer to maintain thread-safety with jobs. - If you need to extend or hook into this behavior, consider creating a system that runs after this system or intercepts the Event's TargetElement buffer since SubmergeSystem writes target entities into those buffers.