I'm trying to understand WaitForEndOfFrame and almost figured, but the problem is when the first yield
is encountered, it skips and save it for the next frame, and in the next frame it is resumed at the end of the rendering, but it's called twice, and it continues to work as expected for the rest of the frames.
can't find out why the expected code after yield
is called twice in the second frame.
void Update()
{
print("1 - " + Time.frameCount);
StartCoroutine(Enu());
print("3 - " + Time.frameCount);
}
IEnumerator Enu()
{
print("2 - " + Time.frameCount);
yield return new WaitForEndOfFrame();
print("4 - " + Time.frameCount);
}
1 - 1
2 - 1
3 - 1
--
1 - 2
2 - 2
3 - 2
4 - 2
4 - 2 <-- ?
--
1 - 3
2 - 3
3 - 3
4 - 3
--
1 - 4
2 - 4
3 - 4
4 - 4
--
1 - 5
2 - 5
3 - 5
4 - 5
2
... You could check that out better by passing theframeCount
as parameter into your routine and let it print the parameter in order to see for which frame it got continued .. currently on my phone so can't test it myself – Radiosurgeryyield return null;
you continue the routine at a complete different moment and actually delay them all into the next frame (after all Update calls of the next frame are done). It doesn't replaceWaitForEndOfFrame
which is e.g. quite essential for anything you want to do right after all calculations but before the frame gets rendered (e.g. enable/disable something, after effects etc) – Radiosurgery