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.
Both
yield return 0
andyield return null
yields for a single frame. The biggest difference is thatyield return 0
allocates memory because of boxing and unboxing of the0
that happens under the hood, butyield return null
does not allocate memory. Because of this, it is highly recommended to useyield return null
if you care about performance.You could even just "yield return;" i think,the end result is the same, regarding the coroutine;
Yield return is like saying "Return control now to the caller, but when i am called again continue from my previous state"