Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

OnDemandRendering, coroutine and Time.deltaTime

Discussion in '2019.3 Beta' started by lyha, Dec 24, 2019.

  1. lyha

    lyha

    Joined:
    Feb 28, 2016
    Posts:
    15
    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.
     
  2. lloydv

    lloydv

    Joined:
    Sep 15, 2015
    Posts:
    55
    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.
     
    Prodigga likes this.
  3. lyha

    lyha

    Joined:
    Feb 28, 2016
    Posts:
    15
    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.