- Home /
yield return WWW stops Coroutine?
Update:
I tried replicating the scenario by writing this code and got the same results.
thisWillCheck will never be 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;
}
Original post:
I recently tried using "yield return www;" in my coroutine and got something unexpected.
This is my code:
while(!checkForObject)
{
//Player cancels halfway during check
if(cancel)
{
print ("stopped");
cancel = false;
yield break;
}
yield return new WaitForSeconds(0.5f);
www = new WWW("http://website.com");
yield return www;
print ("Checking objects");
if(www.error != null)
{
print ("No connection");
}
}
If www is returned null at first (Internet connection lost), and suddenly returned with a value (reconnected), my coroutine will end abruptly, it is not caused by player input. 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! :)
Your answer
Follow this Question
Related Questions
How to imitate yield functionality like WWW class 0 Answers
Can I use WWW in Start()? 1 Answer
NullReferenceException in nested Coroutine 0 Answers
How to yiled a try/catch block? 2 Answers