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
0
Question by artie · Aug 30, 2013 at 06:04 AM · coroutineupdatewwwdebug

How to debug a coroutine?

I'm trying to fire an IEnumerator (C#) routine from Update. I can see that the line gets there in Update, I set a break point there ok. But breakpoints in the coroutine are never hit, and nothing seems to happen. It's like the routine is not called, and I don't know why.

 public class FrameUploader : MonoBehaviour
 {
     public Texture2D texture;
     public float frameRate = 1f;
     public string prepend = "user0_";
     public int frameNum = 0;
     public bool showing = true;
     public string server = "http://myserver/uploadimage.php";
     
     float lastFrameTime = 0f;
     int q = 0;
         
     // May want to do this on physics update or late update?
     void Update ()
     {
         if ((Time.time - lastFrameTime) >= 1f/frameRate)
         {
             lastFrameTime = Time.time;
             QueueTexture(); // It gets here, if I set a breakpoint here
         }
     }
     
     IEnumerator QueueTexture()
     {
         // Cannot stop at any breakpoints here. 'q' never changes according to OnGUI
         WWW wwwToUpload = null;
         byte[] bytes = texture.EncodeToPNG();
         WWWForm form = new WWWForm();
         form.AddField("frameNum", frameNum);
         form.AddBinaryData("fileUpload", bytes, prepend+frameNum+".png", "image/png");
         wwwToUpload = new WWW (server+frameNum, form);
         q++;
         frameNum++;
         yield return wwwToUpload;
         wwwToUpload = null;
         form = null;
         q--;
     }
     
     void OnGUI()
     {
         if (showing)
         {
             GUI.Label (new Rect (10, Screen.height-30, 200, 20), "Q: "+q);
         }
     }
 }
Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Aug 30, 2013 at 06:47 AM

You didn't start the coroutine. You have to used StartCoroutine

     StartCoroutine( QueueTexture() );
Comment
Add comment · Show 2 · 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 artie · Aug 30, 2013 at 04:35 PM 0
Share

I had put 'return yield StartCoroutine' as seen in an example in the manual, which didn't work, so I abandoned that. So close. Thanks.

avatar image Bunny83 · Aug 30, 2013 at 08:35 PM 0
Share

Well, that's because "return yield" doesn't exist but "yield return" ;).

However when you use yield return the calling function will also be a coroutine. You can't use yield in a normal function.

avatar image
0

Answer by dreasgrech · Aug 30, 2013 at 08:48 AM

QueueTexture returns an IEnumerator, and you're ignoring that return value; that's why nothing is happening. The coroutine is not being started.

You will need to start it with StartCoroutine(QueueTexture());

which is the same as

 IEnumerator queueTextureCoroutine = QueueTexture();
 StartCoroutine(queueTextureCoroutine);
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

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

18 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

Related Questions

Coroutine is not called between frames 2 Answers

Weapons that used to work got broken after update - has StopAllCoroutines() stopped working? 0 Answers

Yielding with WWW in Editor 9 Answers

Wait load scene until finish load menu 1 Answer

Why isn't this coroutine fully firing? 1 Answer


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