What is the difference between "yield return 0" and "yield return null" in Coroutine?

yumugee picture yumugee · Sep 1, 2016 · Viewed 10.2k times · Source

I'm new and a bit confused about "yield". But finally I understand how it worked using WaitForSeconds

but I can't see the difference between of "yield return 0" and "yield return null".

are both them waiting for the next frame to execute?

sorry for my bad English. Thank you very much.

Answer

Programmer picture Programmer · Sep 1, 2016

Both yield return 0 and yield return null yields for a single frame. The biggest difference is that yield return 0 allocates memory because of boxing and unboxing of the 0 that happens under the hood, but yield return null does not allocate memory. Because of this, it is highly recommended to use yield return null if you care about performance.