Skip to content

Game.Simulation.EventTickSystem

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

Type: class

Base: GameSystemBase

Summary:
EventTickSystem is a simulation System that ticks "Event" entities each simulation frame (scheduled with a lowered update frequency). It runs a Burst-compiled IJobChunk (EventTickJob) which: - Iterates Event entities that have a TargetElement dynamic buffer. - Prunes TargetElement entries whose target entity no longer references this event (by checking a set of possible relation components such as OnFire, AccidentSite, InvolvedInAccident, FacingWeather, HealthProblem, Destroyed, SpectatorSite, Criminal, Flooded, AttendingMeeting). - If an Event has an empty TargetElement buffer and either has no Duration component or its Duration.m_EndFrame <= current simulation frame, the system adds a Deleted component to that Event (via an EndFrameBarrier EntityCommandBuffer). The job is scheduled in parallel and the EndFrameBarrier is used to defer structural changes to the end of the frame. The system uses cached TypeHandles (TypeHandle nested struct) and ComponentLookup handles to access data efficiently.


Fields

  • private EndFrameBarrier m_EndFrameBarrier
    Used to create an EntityCommandBuffer for deferring structural changes (adding Deleted component). It's obtained from the world in OnCreate.

  • private SimulationSystem m_SimulationSystem
    Reference to the SimulationSystem used to read the current simulation frame index (m_SimulationSystem.frameIndex).

  • private EntityQuery m_EventQuery
    EntityQuery selecting Event entities to process. Constructed as:

  • ReadOnly: Game.Events.Event
  • ReadWrite: TargetElement (buffer)
  • Excludes: Deleted, Temp

  • private TypeHandle __TypeHandle
    Nested struct instance that caches EntityTypeHandle, ComponentTypeHandle, BufferTypeHandle, and multiple ComponentLookup handles for the various relationship components (OnFire, AccidentSite, InvolvedInAccident, FacingWeather, HealthProblem, Destroyed, SpectatorSite, Criminal, Flooded, AttendingMeeting). Populated in OnCreateForCompiler / __AssignHandles.

Properties

  • None (no public properties on EventTickSystem).

Constructors

  • public EventTickSystem()
    Default parameterless constructor. The system performs initialization in OnCreate / OnCreateForCompiler.

Methods

  • public override int GetUpdateInterval(SystemUpdatePhase phase)
    Returns 256. This system is configured to run with an update interval of 256 (reducing how often it updates relative to every frame).

  • [Preserve] protected override void OnCreate()
    Initializes system references:

  • Gets/creates the EndFrameBarrier and SimulationSystem from the World.
  • Creates the m_EventQuery (Event + TargetElement, excluding Deleted and Temp).
  • Calls RequireForUpdate(m_EventQuery) so the system only runs if there are matching entities.

  • [Preserve] protected override void OnUpdate()
    Builds and schedules the Burst-compiled EventTickJob:

  • Passes current simulation frame (from m_SimulationSystem).
  • Passes a parallel EntityCommandBuffer from the EndFrameBarrier.
  • Passes cached entity/type/buffer/component lookup handles (via InternalCompilerInterface wrappers).
  • Schedules the job with JobChunkExtensions.ScheduleParallel and attaches its handle to the EndFrameBarrier with AddJobHandleForProducer.

  • private void __AssignQueries(ref SystemState state)
    Called by the compiler helper OnCreateForCompiler. It currently creates (and disposes) an empty EntityQueryBuilder (placeholder in generated code).

  • protected override void OnCreateForCompiler()
    Compiler helper that calls __AssignQueries and assigns handles on the nested __TypeHandle via __AssignHandles.

  • (Nested) EventTickJob : IJobChunk (Burst compiled)
    Job that executes the per-chunk logic:

  • Reads entity array and Duration component array, gets TargetElement buffer accessor.
  • For each entity in the chunk, iterates its TargetElement dynamic buffer and removes any entries whose target entity does not reference this event according to any of the relation components (OnFire, AccidentSite, InvolvedInAccident, FacingWeather, HealthProblem, Destroyed, SpectatorSite, Criminal, Flooded, AttendingMeeting).
  • If the buffer becomes empty and (no Duration present OR Duration.m_EndFrame <= simulationFrame), it adds a Deleted component to the event via the parallel command buffer.
  • The job is compatible with parallel scheduling and uses ComponentLookup.HasComponent / indexer to check the target entity relationships.

  • (Nested) TypeHandle.__AssignHandles(ref SystemState state)
    Initializes all internal handles (EntityTypeHandle, ComponentTypeHandle readonly, BufferTypeHandle, and multiple ComponentLookup<> readonly handles) from the provided SystemState.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // Typical initialization done by the system:
    m_EndFrameBarrier = World.GetOrCreateSystemManaged<EndFrameBarrier>();
    m_SimulationSystem = World.GetOrCreateSystemManaged<SimulationSystem>();
    m_EventQuery = GetEntityQuery(
        ComponentType.ReadOnly<Game.Events.Event>(),
        ComponentType.ReadWrite<TargetElement>(),
        ComponentType.Exclude<Deleted>(),
        ComponentType.Exclude<Temp>()
    );
    RequireForUpdate(m_EventQuery);
}

Additional notes: - The job is Burst-compiled for performance and scheduled in parallel; it uses low-level ECS APIs (EntityTypeHandle, BufferTypeHandle, ComponentLookup) and must be used in a DOTS-compatible environment. - The system relies on the semantics of various relation components (OnFire, AccidentSite, etc.) where those components contain a field referencing the originating Event (m_Event or m_Meeting). If those relation components are removed or no longer point to the event, the TargetElement is pruned. - Structural changes (adding Deleted) are deferred using the EndFrameBarrier's EntityCommandBuffer to avoid modifying archetypes while chunks are being processed.