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

前端 未结 2 1031
深忆病人
深忆病人 2021-02-13 12:49

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 betwee

相关标签:
2条回答
  • 2021-02-13 13:12

    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.

    0 讨论(0)
  • 2021-02-13 13:20

    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"

    0 讨论(0)
提交回复
热议问题