• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by LandonC · Apr 16, 2018 at 03:28 AM · coroutinewwwyieldconnectioninternet

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! :)

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

87 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

yield return request never returns 2 Answers

yield on a www never completes 10 Answers

Loading files via WWW class and Unity hangs for a few seconds if I use coroutines. If I don't, it works perfectly. What is going on? 1 Answer

Yielding with WWW in Editor 9 Answers

How to imitate yield functionality like WWW class 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges