Skip to content

Game.EndFrameBarrier

Assembly: Assembly-CSharp
Namespace: Game

Type: class

Base: Unity.Entities.BarrierSystem

Summary: EndFrameBarrier is a synchronization barrier system used by the game's ECS update pipeline to mark the end of a frame's work and to coordinate job-based work that produces data consumed later (or on the main thread). It is intended as a point where producer JobHandles can be stored and later completed, and where systems or AllowBarrier wrappers reference a well-known synchronization point. The SystemOrder registration uses EndFrameBarrier as a MainLoop barrier so many systems can schedule jobs that will be completed at or after this barrier.


Fields

  • private System.Diagnostics.Stopwatch m_Stopwatch Used to measure timing information for the barrier (for example frame timings or debugging/performance metrics). The stopwatch is typically initialized in OnCreate and can be used by derived systems or by the barrier itself to track elapsed times across frames.

  • private Unity.Jobs.JobHandle <producerHandle>k__BackingField Backing field for the producerHandle property. This stores a Unity.Jobs.JobHandle representing work scheduled by producers (jobified systems) that should be awaited/completed by consumers or by the barrier at an appropriate point in the frame.

Properties

  • public Unity.Jobs.JobHandle producerHandle { get; private set } Stores the JobHandle representing jobs produced before the barrier. Systems that produce job work should set this handle (or combine it) so the barrier can ensure the jobs are completed before subsequent non-job work or before systems that must see the produced results. The private setter indicates the handle is intended to be managed by the barrier or closely related systems.

Constructors

  • public EndFrameBarrier() Default constructor. As a BarrierSystem-derived class, typical initialization of internal state is done in OnCreate rather than the constructor. The constructor exists to allow the world to construct the system instance.

Methods

  • protected virtual OnCreate() : System.Void Called when the barrier system is created. Typical responsibilities:
  • Initialize m_Stopwatch (e.g. m_Stopwatch = new Stopwatch()).
  • Reset or initialize producerHandle to JobHandle.Completed.
  • Register any required native containers or dependencies. Derived implementations may call base.OnCreate() first, then perform additional initialization.

Usage Example

[Preserve]
    protected override void OnCreate()
    {
        base.OnCreate();
        m_Stopwatch = new Stopwatch();
    }

Additional notes for modders: - SystemOrder registers EndFrameBarrier to be updated before the MainLoop ends and references it in many UpdateBefore/After calls. To make your system run after all job-producing work that should be finished at frame end, use UpdateAfter() or UpdateBefore/After as appropriate in your mod's system registration. - If your system produces jobs which must be visible to systems running after the barrier, combine your job handles into EndFrameBarrier.producerHandle (or use the barrier's API) so the barrier can ensure completion. Conversely, if you consume data produced before the barrier, make sure to call .Complete() on the provided producerHandle (or use proper dependency chaining) to avoid race conditions. - The AllowBarrier wrapper pattern used in SystemOrder indicates points where modifications are permitted around barriers. Familiarize yourself with AllowBarrier semantics if you need to interpose behavior around EndFrameBarrier.