3

Regarding the duplicate:

I got an answer for this over at GameDev.SE. It's pretty clear that this is not a duplicate, though it is now asked on both sites.

https://gamedev.stackexchange.com/questions/81377/does-yield-return-false-have-special-meaning-in-unity3d-c-scripts


We have this code:

private IEnumerator SomeFunction(/*lots of arguments*/)
{
    // Wait until the local dictionary is loaded
    while (!BundleLibrary.Instance.LocalBundleDictionaryLoaded)
    {
        yield return null;
    }

    //Wait for remote dictionary loaded if needed
    if (BundleConfig.Instance.WaitForRemoteDictionary)
    {
        while (!BundleLibrary.Instance.RemoteBundleDictionaryDownloaded)
        {
            yield return false;
        }
    }
    // more code below here
}

I get that yield return null means the routine will pick up where it left off on the next frame.

But I don't really understand what the yield return false does. I haven't seen it, but I wouldn't know what yield return true would do, either.

Community
  • 1
  • 1
Almo
  • 15,538
  • 13
  • 67
  • 95
  • `RemoteBundleDictionaryDownloaded` doesn't even Google. The only two matches are this question and your pastebin. Can you link to some Unity3D documentation that explains it, or provide a code sample that is a bit more comprehensive? – Robert Harvey Aug 04 '14 at 22:02
  • This question is about what yield return false does. Why does RemoteBundleDictionaryDownloaded have anything to do with it? – Almo Aug 04 '14 at 22:02
  • It's about context. Without it, we're merely discussing contrived code. In the absence of additional context, I don't think returning `false` makes any sense. – Robert Harvey Aug 04 '14 at 22:03
  • @HighCore: Unless that question specifically addresses `yield return false`, it's not a duplicate. – Robert Harvey Aug 04 '14 at 22:04
  • @RobertHarvey how is `yield return false` different from `yield return anythingElse`? – Federico Berasategui Aug 04 '14 at 22:05
  • OK, I'm completely lost. `yield return null` has a definite meaning: the coroutine is called again next frame. `yield return WaitForSeconds(5)` means the coroutine is called again in 5 seconds. Why doesn't `yield return false` have a definite meaning? – Almo Aug 04 '14 at 22:05
  • @HighCore: You mean other than the fact that it doesn't make any sense? – Robert Harvey Aug 04 '14 at 22:06
  • @Almo: Well, I can certainly speculate. `IEnumerator.Current()` returns an object, which means that you can unbox it and get a boolean signal. What that signal means you could probably get from the Unity3D documentation, if suitable documentation exists. – Robert Harvey Aug 04 '14 at 22:09
  • @Almo Are you sure you know how `yield return` works... – I4V Aug 04 '14 at 22:11
  • @I4V No, I am not. But I am finding that there are plenty of places that tell me about the null and waitforseconds cases, but no mention of what true or false do. This example uses them, but I don't see that a true or false return value from the coroutine are used in the code there: http://answers.unity3d.com/questions/469266/using-yield-without-startcoroutine-in-c.html – Almo Aug 04 '14 at 22:17
  • I have read Unity's documentation on coroutines, and it's really not clear at all how these things are supposed to work. Which is why I am asking here. – Almo Aug 04 '14 at 22:23
  • So what this function *does* is create an IEnumerator containing some indeterminate number of nulls (number depends on how long it takes to download the local dictionary and your processor's speed), followed by some number of falses (depends on time to load remote dictionary). Why it does this in the context of Unity I have no idea. – ahruss Aug 04 '14 at 23:35
  • Definitely not a duplicate. Unity's scheduler that deals with coroutines has some interesting things it does with the yield statement. – Almo Aug 05 '14 at 17:12

0 Answers0