How does Invoke cope with mapping on frames

When I would use Invoke(Function,5.0f), Function should be fired in exactly 5 seconds from now. My question roughly is, how exact is this?

Unity works with frames, and it’s quite reasonable to assume that “5 seconds from now” will fall right between 2 frames. How does Unity handle this?

Also when I have 2 coroutines both stating to yield for 5 seconds (or similary have 2 invoke calls with the same specified time), will the order of execution always be maintained? What if they get mapped on the same frame?

Sorry for the vague question.

1 Answer

1

Invokes are processed during the game loop so it will not be “exactly” 5 seconds from when you invoke it - it will be after Update on the frame that is the first frame after the timeout is met. Coroutine and Invoke order should be consistent.

Damn that's exactly what I thought. (Which unfortunately isn't what I hoped for :D)

You could try a thread - but of course that couldn't interact with Unity without syncing with the main loop anyway...

Well it's been a long time, hereby I accept your answer!