- Home /
How does Invoke() work?
How exactly does Invoke() work? Does it transform the invoked method into a Coroutine and insert WaitForSeconds(delay parameter passed to Invoke()) before its first line? Or does it store the delay parameter in a hidden variable and check at the start of each frame if the delay has been reached, thereby causing additional overhead for each check? And when the invoked method is finally run, does it run concurrently with whatever method is currently running (like a coroutine), or does the invoked method get priority?
Answer by sneftel · Jun 18, 2011 at 08:01 PM
It would be difficult to answer the first question without the source code, but I would be surprised if pending delayed invocations were not put into a global priority queue, so the per-invocation overhead should be quite low. As for the second question, I think I recall that they run immediately after the Update()
phase. BTW, coroutines do not run concurrently; only one is active at any given time (all others are yielded).