This document is about: QUANTUM 3

This page has not been upgraded to Quantum 3.0 yet. The information may be out of date.

Elapsed Time


There are two ways to calculate the elapsed time in Quantum:

  • based on the Frame.Number; and,
  • based on the accumulated deltatime.

Time based on the Frame Number

The simplest way calculate the time lapsed since the start of a session is based on frame.Number:

frame.Number * frame.deltaTime;
frame.Number / frame.UpdateRate

Both calculations will return a time in seconds.

Note: frame.Number STARTS at RollbackWindow, not at 0!

This will accurately and deterministically track the total time lapsed, i.e. it will be identical in all game clients at the same tick number.

Extending the Frame

To facilitate access to the result, you could implement the following snippet in the Frame's partial definition of Frame.User.cs:


namespace Quantum {
    unsafe partial class Frame {
        public FP ElapsedTime {
            get {
                return DeltaTime * (Number - SessionConfig.RollbackWindow);

From Unity

From Unity you have access to the SimulationTimeElapsed property in the Deterministic Session.



Note: This returns a double based on the predicted frame number and the simulation delta time. It does not does not take the RollbackWindow into consideration.

You can multiply the current frame number minus the RollbackWindow with the the delta time of a tick.

Accumulate Time as a Global Variable

If you need to change Deltatime at runtime, or want to suspend a game and pick-up it later, you will have to track the accumulated deltatime manually.


// add a global variable to your qtn-file
global {
  FP ElapsedTime;

// create a system
public unsafe class TimeSystem : SystemMainThread {
    public override void Update(Frame f) {
        f.Global->ElapsedTime += f.DeltaTime;

Note: The precision required by FP will eventually lead to inaccuracies. A way to improve precision is to keep track of ticks instead of time; these can be counted using an Int32.

Back to top