Skip to content

Game.EndFrameBarrier

Assembly:
Game.dll

Namespace:
Game

Type:
class

Base:
Unity.Entities.EntityCommandBufferSystem

Summary:
EndFrameBarrier is a barrier-style (end-of-frame) EntityCommandBuffer system used by game simulation systems to queue structural entity changes from jobs and ensure those changes are played back safely at the end of the frame. It provides methods to create EntityCommandBuffer writers (including parallel writers) and to register job handles so the system knows when producers have finished writing commands. Systems use EndFrameBarrier to collect EntityCommandBuffer operations during job execution and to schedule their playback after the producer jobs complete.


Fields

  • private System.Diagnostics.Stopwatch m_Stopwatch
    Used internally to measure time spent applying the buffered entity changes (useful for profiling / diagnostics of the barrier's playback phase).

  • private Unity.Jobs.JobHandle <producerHandle>k__BackingField
    Backed storage for the producerHandle property; tracks the JobHandle representing the work that produced commands for this barrier, allowing the system to wait for producer completion before playback.

Properties

  • public Unity.Jobs.JobHandle producerHandle { get; private set }
    Holds the JobHandle for the current producer(s) that have written to the barrier's command buffer. Systems and the barrier use this to chain dependencies and ensure playback happens only after producers complete. The setter is private; the barrier updates it when producers register their handles.

Constructors

  • public EndFrameBarrier()
    Default constructor; initializes internal state of the barrier system. Typically the system is retrieved/created via World.GetOrCreateSystemManaged().

Methods

  • protected virtual OnCreate() : System.Void
    Initializes the barrier when it is created in the World. Sets up any required internal resources.

  • CreateCommandBuffer() : EntityCommandBuffer
    Creates a new EntityCommandBuffer that will be played back by the barrier at the appropriate time (end of frame). This buffer is used by single-threaded writers.

  • CreateCommandBuffer().AsParallelWriter() : EntityCommandBuffer.ParallelWriter
    Returns a parallel writer for the barrier's EntityCommandBuffer so jobs can write structural changes in parallel. The parallel writer is the commonly used path in simulation jobs.

  • AddJobHandleForProducer(JobHandle producerHandle) : void
    Registers a producer JobHandle with the barrier. The barrier will combine/track these handles so it can schedule playback only after producer jobs have finished. Call this after scheduling jobs that write to command buffers created from this barrier.

  • (Playback / internal scheduling)
    The barrier system handles playback of collected EntityCommandBuffer operations at the end of frame/update stage, optionally recording playback timing (m_Stopwatch) and ensuring dependency chaining via producerHandle.

Usage Example

// typical usage inside a SystemBase/ISystem OnCreate/OnUpdate:
m_EndFrameBarrier = base.World.GetOrCreateSystemManaged<EndFrameBarrier>();

// create a parallel command buffer writer for a job:
var commandBuffer = m_EndFrameBarrier.CreateCommandBuffer().AsParallelWriter();
// schedule jobs that use commandBuffer...
JobHandle jobHandle = JobChunkExtensions.ScheduleParallel(myJob, query, dependency);

// tell the barrier about the producer job so playback waits for it:
m_EndFrameBarrier.AddJobHandleForProducer(jobHandle);

{{ Additional notes: - In the provided DeathcareFacilityAISystem, EndFrameBarrier is used to produce an EntityCommandBuffer.ParallelWriter that the chunk job writes to, and AddJobHandleForProducer is called with the scheduled job handle so the changes are played back safely. - Use EndFrameBarrier when you need to perform structural entity changes from jobs and ensure they are applied after those jobs complete. - For profiling, the barrier may expose internal timing (m_Stopwatch) but that is internal implementation detail; rely on the system's public API (CreateCommandBuffer and AddJobHandleForProducer) for correct usage. }}