Hi there,
Some context: I develop a physics engine for Unity, available in the Asset Store. In this engine, I rely on Unity’s fixed timestep scheme, and perform physics interpolation by keeping track of remaining “unsimulated” time to lerp between physics states.
Recently I’ve been getting multiple reports from users about very strange behavior when building for mobile platforms (iOS and Android).
Upon investigation, seems that Time.deltaTime returns completely incorrect values on these platforms. This is what I do:
float accumulator = 0;
FixedUpdate()
{
accumulator -= Time.fixedDeltaTime;
}
Update()
{
accumulator += Time.deltaTime;
Debug.Log(accumulator);
}
According to Unity’s documentation, FixedUpdate() is called at the beginning of the frame zero, one, or more times. Update() is called once per frame, after all calls to FixedUpdate(). So, if the fixed timestep is 0.02 and last frame’s duration is 0.07 there will be 3 calls to FixedUpdate(), and accumulator should be (-0.02 -0.02 -0.02)+0.07 = 0.01: the remaining “unsimulated” time. FixedUpdate() won’t be called again until the amount of wall clock time accumulated exceeds Time.fixedDeltaTime. A standard fixed timestepping approach, right?
So the expected result is for accumulator to always oscillate between 0 and Time.fixedDeltaTime, since any time added by Update is eventually consumed by FixedUpdate calls.
This has worked fine since Unity 5. However in 2020.2, the accumulator is always some large negative number (between -80 and -150-ish). Only possible explanation is that Time.deltaTime is not reporting accurate timings near startup. This is only reproducible in iOS/Android, afaik.
This completely breaks physics interpolation in these platforms, as I can’t get any reliable time estimation to interpolate physics states. Disabling interpolation is the only workaround, and it results in jittery jitters. It’s a pretty critical issue for me.
Does anyone have encountered this before, or has any change been introduced to the way 2020.2 works that would explain this?