Skip to content

Game.EndFrameBarrier

Assembly: Assembly-CSharp
Namespace: Game

Type: class

Base: Unity.Entities.SystemBase

Summary:
EndFrameBarrier is a managed end-of-frame command buffer system used to collect EntityCommandBuffer commands produced by jobs and play them back at the end of the frame. It exposes an EntityCommandBuffer producer pattern for parallel jobs (via CreateCommandBuffer().AsParallelWriter()) and tracks job handles from producers so the system can ensure playback happens after all producer jobs have completed. It also contains simple timing/profiling support (Stopwatch) used to measure barrier or playback duration in debug builds. This system is commonly obtained with World.GetOrCreateSystemManaged() and used by simulation systems (for example, RideNeederSystem) to create vehicle/taxi requests from jobs.


Fields

  • private System.Diagnostics.Stopwatch m_Stopwatch
    Used for lightweight timing/profiling of the barrier or its playback. Typically populated/started in OnCreate for debug/perf measurements.

  • private Unity.Jobs.JobHandle <producerHandle>k__BackingField
    Backing field that stores the aggregated JobHandle of producer jobs that created commands for this barrier. Kept private; accessed through the public producerHandle property.

Properties

  • public Unity.Jobs.JobHandle producerHandle { get; private set }
    Exposes the current producer JobHandle (readable by other systems). Systems producing command buffers should combine their job Handles into the barrier (via an AddJobHandleForProducer-style method) so the barrier can wait for completion before playback.

Constructors

  • public EndFrameBarrier()
    Constructs the managed system instance. On creation the system will initialize its internal structures (Stopwatch, producer handle) in its OnCreate lifecycle method.

Methods

  • protected virtual OnCreate() : System.Void
    Initializes the EndFrameBarrier system. Typical tasks performed here:
  • Instantiate and initialize m_Stopwatch (for debug timing).
  • Reset/initialize the producer handle.
  • Register any required queries or other setup needed for playback.
    This method can be overridden by derived systems to perform additional setup.

Additional common operations (not shown as explicit methods here but expected behavior): - CreateCommandBuffer() / CreateCommandBuffer().AsParallelWriter() — used by producers to obtain an EntityCommandBuffer (or ParallelWriter) to record structural changes from jobs. - AddJobHandleForProducer(JobHandle) — merge a job handle into the barrier so playback waits for producers.

Usage Example

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

Additional usage pattern (typical): - In a system's OnCreate: m_EndFrameBarrier = World.GetOrCreateSystemManaged(); - In OnUpdate: schedule a parallel job that receives an EntityCommandBuffer.ParallelWriter from m_EndFrameBarrier.CreateCommandBuffer().AsParallelWriter(), then call m_EndFrameBarrier.AddJobHandleForProducer(jobHandle) to register the job's handle so the barrier will wait before flushing recorded commands.