I recently tried using “yield return www;” in my coroutine and got something unexpected.
This is a code to replicate the scenario:
thisWillCheck will never return to false, if internet connection is retrieved halfway.
IEnumerator FindWWW()
{
while(thisWillCheck)
{
print ("Still checking");
yield return null;
}
}
bool thisWillCheck;
IEnumerator JustTesting()
{
WWW www = new WWW("http://google.com");
yield return www;
Debug.Log("CheckingInternet now");
thisWillCheck = true;
StartCoroutine(FindWWW());
while(www.error != null)
{
www = new WWW("http://google.com");
yield return www;
Debug.Log(www);
yield return null;
}
thisWillCheck = false;
}
If www is returned null at first (Internet connection lost), and suddenly returned with a value (reconnected), my coroutine will end abruptly. It was as if it did “yield break”. I tried removing “yield return www” and all things went well.
Please correct me if I’m wrong, initially I thought “yield return www” is similar to “yield return null” when www is not returning a value. But since this is happening, I doubt so.
Can anyone explain what does it actually do? Thanks in advance!