OnDemandRendering, coroutine and Time.deltaTime

Currently working on upgrade project to the 2019.3 and using new feature OnDemandRendering. I’m faced an issue but not sure isn’t it done intentional.
In case FPS is lowered to minimum level (1 FPS) via OnDemandRendering and there is a coroutine for each frame (WaitForEndOfFrame()) with code dependent from Time.deltaTime (in my case Quaternion.Lerp()):

  • Time.deltaTime returns not real length from the last frame - it’s really low (not ~1s)
  • WaitForEndOfFrame waits for drawn frame, means ~1s
    As a result dependent code is working slower - slow rotation in this case.

As I understand it (I could be wrong since I haven’t had a chance to use ODR personally yet), Time.deltaTime and the frequency at which Update() is called is not affected by OnDemandRendering, only whether or not the screen is redrawn. WaitForEndOfFrame on the other hand is a post-rendering callback, so I imagine it is only called when something is actually drawn.

So if you’re rendering at 1fps (which according to the documents is too infrequent and not recommended), the time between executions of WaitForEndOfFrame calls is 1 second, but Time.deltaTime is still just the time since the previous Update loop. Therefore it makes sense to me that your animation would be 60x slower.

1 Like

Thank you, it’s pretty important engine basics I’ve missed.
Mostly I felt confused because coroutines did not have a way to work with ODR.
Also it’s a good case to see the difference between yield return WaitForEndOfFrame and yield return null.