Class TimeStepApplier
Takes explicit control of Unity's time loop and advances simulation time only when Step(double) is called, enabling deterministic stepped simulation.
Inherited Members
Namespace: Unity.SimulationPro.Foundation.ClockManagement
Assembly: Unity.SimulationPro.Foundation.dll
Syntax
[DisallowMultipleComponent]
public sealed class TimeStepApplier : MonoBehaviour
Remarks
At most one enabled instance may exist at a time. Use Instance or GetOrCreateInstance() to obtain the singleton. Call EnsureSimulatedTime() to create and activate the FoundationClock mode automatically.
Fields
DEBUG_DoManualStep
Debug flag: triggers a single manual time step on the next Update when set to true.
Declaration
public bool DEBUG_DoManualStep
Field Value
| Type | Description |
|---|---|
| bool |
DEBUG_ManualStepSize
Debug field: controls the size of the manual time step triggered by DEBUG_DoManualStep.
Declaration
[Range(0.001, 10)]
public float DEBUG_ManualStepSize
Field Value
| Type | Description |
|---|---|
| float |
Properties
AllowTimeAccumulation
Gets or sets a value indicating whether multiple calls to Step(double) within the same frame are allowed to accumulate rather than being rejected as errors.
Declaration
public bool AllowTimeAccumulation { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ElapsedFixedUpdateTime
Gets the total simulated time in seconds accumulated by physics (FixedUpdate) steps.
Declaration
public double ElapsedFixedUpdateTime { get; }
Property Value
| Type | Description |
|---|---|
| double |
Remarks
May be off by one FixedUpdate delta when queried during the same FixedUpdate cycle unless this component's script execution order is set to run before all other scripts.
Instance
Gets the active, enabled TimeStepApplier instance, or null if none exists.
Declaration
public static TimeStepApplier Instance { get; }
Property Value
| Type | Description |
|---|---|
| TimeStepApplier |
IsInitialized
Gets a value indicating whether this instance has completed initialization.
Declaration
public bool IsInitialized { get; }
Property Value
| Type | Description |
|---|---|
| bool |
LastFramePhysicsUpdated
Gets the frame index of the most recent FixedUpdate in which physics was simulated.
Declaration
public int LastFramePhysicsUpdated { get; }
Property Value
| Type | Description |
|---|---|
| int |
LastFrameStepRequested
Gets the frame index of the most recent frame in which Step(double) was called.
Declaration
public int LastFrameStepRequested { get; }
Property Value
| Type | Description |
|---|---|
| int |
LastFrameStepped
Gets the frame index of the most recent frame in which a time step was fully resolved.
Declaration
public int LastFrameStepped { get; }
Property Value
| Type | Description |
|---|---|
| int |
TimeAtFrameStart
Gets the simulated time in seconds at the start of the current frame, including any pending accumulation from the previous frame's step request.
Declaration
public float TimeAtFrameStart { get; }
Property Value
| Type | Description |
|---|---|
| float |
TotalTimeRequested
Gets the total simulated time in seconds that has been requested via Step(double).
Declaration
public double TotalTimeRequested { get; }
Property Value
| Type | Description |
|---|---|
| double |
Methods
GetOrCreateInstance()
Returns the existing TimeStepApplier instance, or creates and initializes a new one on a new GameObject if none is found.
Declaration
public static TimeStepApplier GetOrCreateInstance()
Returns
| Type | Description |
|---|---|
| TimeStepApplier | The active TimeStepApplier singleton. |
HardInitialize()
This will immediately initialize the TimeStepApplier, even if it has already been initialized once -- this is useful when doing multiple simulation runs in the same scene
Declaration
public void HardInitialize()
Step(double)
Requests that simulation time advance by the specified delta on the next rendered frame.
Declaration
public void Step(double requestedTimeDelta)
Parameters
| Type | Name | Description |
|---|---|---|
| double | requestedTimeDelta | The amount of simulated time in seconds to advance. Must be greater than zero. |
Remarks
If called more than once in the same frame and AllowTimeAccumulation is false, an error is logged and the second call is ignored.