Skip to content

Game.EndFrameBarrier

Assembly: Assembly-CSharp (most Cities: Skylines 2 mod types live in Assembly-CSharp)
Namespace: Game

Type: class

Base: Unity.Entities/System base (barrier-style system used to synchronize jobs at frame end)

Summary:
EndFrameBarrier is a small ECS-style barrier system used to coordinate and finalize job work at the end of a frame. It keeps a stopwatch for rudimentary timing/profiling and stores a producer JobHandle so the system can ensure scheduled jobs are completed or chained correctly before the frame finishes. This type is useful in mod code that schedules Unity.Jobs from game systems and needs a central point to complete or observe those job handles at the end of the frame.


Fields

  • private System.Diagnostics.Stopwatch m_Stopwatch
    Used for simple timing/profiling of the barrier's activity (for example, to measure how long job completion or barrier work takes). This Stopwatch is typically initialized in OnCreate and may be used only in development/profiling builds to avoid runtime overhead.

  • private Unity.Jobs.JobHandle <producerHandle>k__BackingField
    Backing field for the producerHandle property. It holds the JobHandle produced by systems that schedule work intended to be completed/observed by this barrier. The field is used internally to track dependency chains between scheduled jobs and the barrier.

Properties

  • public Unity.Jobs.JobHandle producerHandle { get; private set }
    Public getter exposes the JobHandle that the barrier is tracking so other systems can read the current producer's handle if needed. The setter is private, indicating the barrier manages this field itself (external code should not set it directly). In typical usage the barrier will read this handle to complete or combine it with other handles when finalizing frame work.

Constructors

  • public EndFrameBarrier()
    Default constructor. In an ECS context the constructor will be used by the runtime to create the system; initialization of runtime resources (like the Stopwatch) is normally done in OnCreate rather than the constructor.

Methods

  • protected virtual OnCreate() : System.Void
    OnCreate is used to perform initialization when the system is created by the entity/system manager. Typical tasks include:
  • Initializing m_Stopwatch (e.g., m_Stopwatch = new Stopwatch()).
  • Setting up update order or requirements (so the barrier runs at the correct point in the frame).
  • Preparing any internal JobHandle state or clearing previous handles. Override this method in subclasses to perform additional setup while calling base.OnCreate().

Usage Example

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

Notes and modding tips: - Use this barrier as the canonical point to complete or combine job handles that represent per-frame work. Completing producerHandle here avoids race conditions where jobs outlive the frame in unexpected ways. - Keep heavy profiling code behind development build checks; the Stopwatch is convenient for ad-hoc timing but can add overhead. - Because the property has a private setter, other systems cannot assign producerHandle directly — check the actual implementation in-game or expose an API if you need to register a handle with the barrier. - If you rely on specific ECS base classes or update groups (for example, ensuring this runs after rendering or AI systems), verify the real base class and update order in the decompiled game assembly so your mod integrates correctly.