Alright so I understand that a yield are basically like bookmarks of code. However, I thought they were bookmarks until the next time the function is called. It seems that a yield is simply a “return here on the next frame” – Don’t get me wrong, it works perfectly. But I guess I don’t really understand them. Here’s my simple test that leads me to believe that yield is pretty much a frame break.
void Start ()
{
StartCoroutine(Go());
}
IEnumerator Go()
{
print("hit1" + "-" + Time.frameCount);
yield return null; //return next frame
print("hit2" + "-" + Time.frameCount);
yield return null; //return next frame
print("hit3" + "-" + Time.frameCount);
yield return null; //return next frame
print("hit4" + "-" + Time.frameCount);
yield return null; //return next frame
print("end" + "-" + Time.frameCount);
yield break;
}
So just to make sure, is yield pretty much just a “check back in on the next frame”?
This is the output:
hit1-1
hit2-2
hit3-3
hit4-4
end-5