Game.EndFrameBarrier
Assembly:
Assembly-CSharp (typical for game code / mods)
Namespace:
Game (used as a global / game-level system in this project)
Type:
System (runtime system used to coordinate end-of-frame command buffer execution)
Base:
Barrier-like system for end-of-frame EntityCommandBuffer management (conceptually similar to Unity.Entities.EndSimulationEntityCommandBufferSystem / BarrierSystem)
Summary:
EndFrameBarrier is a system used by the simulation to create EntityCommandBuffers for jobs and to manage job dependencies (producer job handles) so that commands recorded by background jobs are played back safely at the end of the frame. It exposes a mechanism to create command buffers (including parallel writers) and to register JobHandles produced by jobs so the system can wait for completion before applying the recorded entity changes. Internally it tracks timings (for profiling) and the current producer JobHandle.
Fields
-
private System.Diagnostics.Stopwatch m_Stopwatch
Used internally to measure timing/profiling information for the barrier (e.g., how long playback or command collection takes). It is typically initialized in OnCreate. -
private Unity.Jobs.JobHandle <producerHandle>k__BackingField
Backing field that stores the current producer JobHandle. This handle represents the job(s) that produced commands for the barrier and must be tracked so playback can wait for those jobs to complete.
Properties
public Unity.Jobs.JobHandle producerHandle { get; private set }
Accessor for the producer JobHandle. The getter exposes the JobHandle representing the currently-registered producing work; the setter is private and used by the barrier to update the handle when jobs are scheduled. Mod systems use AddJobHandleForProducer (or similar API) to register their JobHandle with the barrier which then stores/combines it into this property.
Constructors
public EndFrameBarrier()
Default constructor. The system will typically initialize internal data structures and the stopwatch during OnCreate rather than doing expensive work in the constructor.
Methods
protected virtual OnCreate() : System.Void
Called when the system is created. Typical responsibilities:- Initialize the m_Stopwatch for optional profiling.
- Create any internal state required to track producer JobHandles.
- Register the system with the world (handled by the framework). Implementations often call base.OnCreate() and then set up the stopwatch and any other initial state.
Other relevant methods (not listed in the minimal template) commonly provided by this kind of barrier system: - CreateCommandBuffer() : EntityCommandBuffer — returns an ECB used to record entity operations. - CreateCommandBuffer().AsParallelWriter() — returns a parallel writer variant for use inside parallel jobs. - AddJobHandleForProducer(JobHandle jobHandle) : void — register/merge a producer job handle so the barrier will wait for it before playback (this is used in CreatureSpawnerSystem.AddJobHandleForProducer). - Possibly methods to play back the recorded commands at the end of frame.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_Stopwatch = new Stopwatch();
}
{{ ADDITIONAL_INFO }}
- Typical usage pattern from CreatureSpawnerSystem:
- Acquire the EndFrameBarrier instance in OnCreate:
m_EndFrameBarrier = base.World.GetOrCreateSystemManaged
- Notes for modders:
- Always register job handles produced by recorded-command-writing jobs with the barrier (via AddJobHandleForProducer or equivalent) so that playback happens after job completion.
- Use the parallel writer variant (AsParallelWriter) when recording commands from parallel jobs and pass the chunk/job index into command buffer calls where required.
- The EndFrameBarrier patterns mirror Unity's EntityCommandBufferSystem/EndSimulationEntityCommandBufferSystem patterns; if you are familiar with those, treat this system similarly.