Search Unity

Tracking Current Frame Length

Discussion in 'Editor & General Support' started by dpmontes, Sep 22, 2020.

  1. dpmontes

    dpmontes

    Joined:
    Dec 7, 2018
    Posts:
    14
    Is there a good way to track how long the current frame has lasted? I have a lot of work that needs to be performed on many gameobjects such as moving them. They don't all necessarily need to be moved in the same frame. So my thinking is that I could move some of them and then yield return null within the coroutine so that the rest of them will wait until the next frame. The problem is that I don't know exactly how many can be done within a frame. And I would rather not just arbitrarily pick a certain number since the time per gameobject could fluctuate. So if there was some way of knowing when I have reached some threshold of say 10ms of processing them, then I should yield. Is the best way to just capture the Time.time and measure that after each unit of work and then decide if I want to yield at that time or continue working? Or is there some other function like Time.currentFrameDuration that I should be using? Thanks
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
  3. dpmontes

    dpmontes

    Joined:
    Dec 7, 2018
    Posts:
    14
  4. adamgolden

    adamgolden

    Joined:
    Jun 17, 2019
    Posts:
    1,555
  5. dpmontes

    dpmontes

    Joined:
    Dec 7, 2018
    Posts:
    14