- Home /
WaitForEndOfFrame vs Time.frameCount
I'm starting a coroutine inside a monobehaviour, in which I print frame count in the beginning and in the end. In-between I have a WaitForEndOfFrame. Wierdly, the frame counter is the same. How is that possible?
private IEnumerator SampleCoroutine()
{
Debug.Log(Time.frameCount);
yield return new WaitForEndOfFrame();
Debug.Log(Time.frameCount);
}
More wierdly yield return null works correctly here. I saw before this topic https://answers.unity.com/questions/755196/yield-return-null-vs-yield-return-waitforendoffram.html and I thought they are similar and should always return and wait to the next frame.
Answer by Eno-Khaon · Nov 24, 2020 at 09:11 AM
When you use WaitForEndOfFrame(), you're waiting until the trailing end of the current frame before you resume operation on that coroutine. You're not waiting until the next frame.
By contrast, yield return null; is the standard way of saying "wait until the following frame"
Edit: Essentially, you can think of it like the difference between Update() and LateUpdate() functions. This would be kind've like passing data between them, localized into the coroutine's processing cycle.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Coroutine without MonoBehaviour 6 Answers
Problem with attaching scripts to objects 1 Answer
Why does MonoBehaviour not allow message functions to be overridden? 1 Answer