Skip to content

Game.EndFrameBarrier

Assembly:
Namespace:

Type:

Base:

Summary:
A managed end-of-frame barrier system used to collect and synchronize JobHandles produced by systems during the frame. Commonly obtained via World.GetOrCreateSystemManaged() and used by systems that schedule jobs (for example via JobChunkExtensions.ScheduleParallel). After scheduling, producer systems call AddJobHandleForProducer(JobHandle) on this barrier to ensure the produced work is tracked and completed before the end of the frame or before dependent systems execute in the next frame. The barrier is useful for coordinating multi-threaded job work and ensuring proper ordering between producer and consumer systems (e.g., when producers write to buffers/components that consumers will read).


Fields

  • private System.Diagnostics.Stopwatch m_Stopwatch
    Used for optional timing/profiling inside the barrier. Implementations commonly use a Stopwatch to measure how long end-of-frame sync or internal operations take for diagnostics. Initialised in OnCreate in some usages.

  • private Unity.Jobs.JobHandle <producerHandle>k__BackingField
    Backing field that stores the combined JobHandle representing all producer jobs that have been registered with this barrier. Systems add their job handles to the barrier so the barrier can combine or track them for synchronization.

Properties

  • public Unity.Jobs.JobHandle producerHandle { get; private set }
    Exposes the combined JobHandle of all producer jobs registered with the barrier. The getter lets other systems read the handle to create dependencies; the setter is private and managed by the barrier. Reading this handle allows consumer systems to depend on all producer work finishing.

Constructors

  • public EndFrameBarrier()
    Default constructor for the managed barrier system. Typical initialization of internal state is performed in OnCreate rather than the constructor when used as a Unity ECS system.

Methods

  • protected virtual OnCreate() : System.Void
    Initialises the barrier when the system is created. Typical tasks performed here include creating internal timing/profiling objects (e.g., Stopwatch), initializing the producer handle, and registering any required resources. When overriding, call base.OnCreate() first. Example usage in other systems: obtain the barrier instance in OnCreate via base.World.GetOrCreateSystemManaged() and then use it later in OnUpdate.

Additional commonly-used method (not shown above but typically available on such barrier systems): - AddJobHandleForProducer(Unity.Jobs.JobHandle handle) — register a JobHandle produced by a system so the barrier can ensure it is completed at the appropriate synchronization point. Producer systems should call this after scheduling their jobs (for example: m_EndFrameBarrier.AddJobHandleForProducer(base.Dependency)).

Usage Example

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

Notes: - Typical workflow: a system schedules jobs and sets base.Dependency; it then calls m_EndFrameBarrier.AddJobHandleForProducer(base.Dependency) so the barrier is aware of the produced work. - Consumers of data produced by these jobs should create dependencies on the barrier's producerHandle (or otherwise ensure ordering) to avoid race conditions.