- Home /
What does "yield return xxx;" mean? I know that "yield" means to delay the coroutine until the next frame and "return" means to get some value back, but what does it mean when they are used together?
I've learnt most of my scripting knowledge from internet so I don't know much about the fundamentals of programming. A lot of the times I use "yield return null" at the end of coroutines because I fell that's just something you do, but I don't exactly know what "yield return xxx" means when they are used together (although I know what "yield" and "return" means when they are used alone).
So what does "yield return xxx" mean?
E.g.
IEnumerator LoadScene()
{
async = Application.LoadLevelAsync(sceneName);
async.allowSceneActivation = false;
yield return async;
}
Why "yield return async" and not just "yield return null"?? Much thanks!
Answer by flaviusxvii · Sep 06, 2014 at 06:48 PM
http://docs.unity3d.com/412/Documentation/ScriptReference/index.Coroutines_26_Yield.html
That gives you a high level overview of the mechanic, but it has to do with the IEnumerator return type. This makes the function act like a collection when the unity engine "iterates" over it. yield allows it to return a series of values (waits usually) without trashing the function scope each time.
Hi I'm sorry but I don't understand what you mean... (I don't know what "collection", or "trashing" "function scope mean"...)
So, uhm, what exactly is "yield return async" doing that "yield return null" can't do?? :(
Your answer
Follow this Question
Related Questions
Pause the coroutine inside a loop 1 Answer
Returning from and waiting for a Message function 0 Answers
Corutine not behaving like it should? 1 Answer
Using yield to pause a function and start another one. 1 Answer
In coroutin function,if(x) { yield return a } . if(y) { yield return b }. Is it possible? 0 Answers