Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
2
Question by robertbu · Jul 08, 2012 at 05:53 AM · coroutinewwwyield

yield on a www never completes

I'm using code to load a texture from the net that is only a minor variation from the code in the Scripting reference.

 IEnumerator LoadThumbnailFromNet(string stName)
 {
     string stURL = "http://www.mywebsite.com/pano/thumbs/" + stName;
     www = new WWW(stURL);
     
     yield return www;
     Debug.Log("After the yield");  // This line never executed.
 }
 

The problem is that it never gets past the yield. The Debug.Log() statement is not executed. The texture is being loaded. If I drop this code:

 void Update ()
 {
     if (!bLoaded && www != null && www.isDone)
     {
         if (www.texture != null)
             renderer.material.mainTexture = www.texture;
         bLoaded = true;
     }
 }

The flag isDone does go to true and the thumbnail is loaded. Suggestions? I'm I piling up unfinished coroutines as I load each thumbnail? Is there a way for me to watch coroutines?

== Rob ==

Comment
Add comment · Show 1
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
avatar image Andre999 · Apr 15, 2016 at 02:04 PM 0
Share

Hi sir. i see u Profesional in Unity. please help me please. visit my question ini here

http://answers.unity3d.com/questions/1171335/how-to-get-speed-move-swipe-2d-at-game-hockey-in-u.html?sort=votes

10 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jul 08, 2012 at 06:22 PM

Where and how do you execute your coroutine and what other "states" are changed? Time.timeScale == 0? Do you test in the Editor or in a build? What's your build target? Webplayer, Standalone, mobile?

Are you sure that the Gameobject and the script instance where this coroutine runs on is not destroyed?

Comment
Add comment · Show 3 · Share
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
avatar image robertbu · Jul 08, 2012 at 10:18 PM 0
Share

timeScale = 1.0, tested in the editor on a mac, build target is iOS, the game object is not destoryed and is enabled. Is ther any place I can view a list of active coroutines?

avatar image Bunny83 · Jul 09, 2012 at 01:50 AM 1
Share

No, coroutines run on the script instance from which you called StartCoroutine. Unity's coroutine manager is internally and you can't enumerate them.

When i do what you did, everything works as expected. Are you sure you don't get any errors? Have you checked the logfile?

avatar image Bunny83 · Jul 09, 2012 at 11:37 AM 0
Share

Any insight in how and where you call this function?

avatar image
-2

Answer by ProudOne · Jul 08, 2012 at 11:30 AM

Not an expert on yields - but programmer's logic tells me that maybe the 'return' is the problem. Return generally ends the execution of a function. If you take a look at

http://docs.unity3d.com/Documentation/ScriptReference/WaitForSeconds.html

there's no return. Maybe try it without. Hope that helps.

Comment
Add comment · Show 1 · Share
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
avatar image robertbu · Jul 08, 2012 at 04:20 PM 1
Share

Thanks for the suggestion. This is C# code. The WaitForSeconds example in C# reads:

yield return new WaitForSeconds(5);

avatar image
0

Answer by Polymo · Jul 08, 2012 at 07:02 PM

When i do something like this i check www.error != null or www.text != null. I dont think www != null will work.

Comment
Add comment · Show 3 · Share
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
avatar image Bunny83 · Jul 08, 2012 at 10:08 PM 0
Share

Did you read the question?

avatar image Polymo · Jul 09, 2012 at 11:00 AM 0
Share

Yes i did. I thought this was the problem (www !=null never beco$$anonymous$$g a valid result) but it seems i only misread the code. Now i think its the yield "return" <- because it ends the current coroutine. yield www should then do it. At least for me it does work that way.

avatar image Bunny83 · Jul 09, 2012 at 12:22 PM 0
Share

This is C#, not UnityScript. The yield statement have to look like this. It's always yield return ; in C#. Also the yield statement does exit the function, that's the point of yield. It ter$$anonymous$$ated the execution and returns an object to the scheduler. The scheduler will deter$$anonymous$$e when this coroutine should be resumed.

A coroutine is not just a function, it's an object that is stored and managed by the scheduler.

avatar image
0

Answer by nventimiglia · Jul 08, 2012 at 05:38 PM

Here is some code that works for me

  IEnumerator WWWRoutine()
     {
         var form = new WWWForm();
         form.AddField("blah", blah);
 
         var www = new WWW(Url, form);
 
         yield return 1;
 
         yield return www;
 
         if (!string.IsNullOrEmpty(www.error))
         {
             // handle error
         }
         else
         {
            // handle success
         }
     }
Comment
Add comment · Show 1 · Share
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
avatar image Bunny83 · Jul 08, 2012 at 06:19 PM 0
Share

This does a POST request ins$$anonymous$$d of a GET request. Besides that it's exactly the same as the code in the question ;)

avatar image
0

Answer by Linus · Jul 09, 2012 at 11:25 AM

Make sure you are calling the function with StartCoroutine(LoadThumbnailFromNet(stName))

Comment
Add comment · Share
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
  • 1
  • 2
  • ›

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.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

How to yiled a try/catch block? 2 Answers

How to set timer for WWW helper? 1 Answer

Yield Problems 2 Answers

yield return WWW stops Coroutine? 0 Answers

yield return request never returns 2 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