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
None of Unity’s Time functions will help you, as they are only refreshed once per frame. Use DateTime.Now.Ticks
. Read it once at the beginning of processing for the current frame, then read again after each object and see how much time has passed.
Ok thanks, I’ll give that a shot!
I use Time.realtimeSinceStartup
for benchmarking, it updates throughout the frame. @PraetorBlue suggestion might be better as the docs don’t seem to have much confidence in it… but it’s worked fine for me.
Ok thanks!