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 nastajus · Jul 04, 2014 at 03:34 AM · c#coroutinemonodevelopcoroutinescoroutine errors

Had difficulties implementing intro to Coroutines from unitypatterns.com. Help?

I can't figure out the cause of the problem. I've tried restarting Unity and rebooting my PC. I've tried passing string and method names. Switching 0 to null made no difference. Nothing ever changes. I'm always consistently getting either 1 Hello when yield comes before Debug.Log, and 2 Hellos when yield comes after. Any ideas??? I literally only put this online to ask this question here. I really think I need to have Coroutines work properly, I don't know what the source of the problem is.

Gist with syntax highlighting: https://gist.github.com/nastajus/e420713c2aa3be04b8cb

Github entire but simple project: https://github.com/nastajus/CoroutinesLearning

Unity Patterns tutorial: http://unitypatterns.com/introduction-to-coroutines/

The most interesting result was when I append i to the output it prints 5 times instead. Very weird and confusing based off the tutorial.

     void Start(){
         StartCoroutine("SayHello5Times");    //doesn't work right
     }

     IEnumerator SayHello5Times(){
         for (int i = 0; i < 5; i++){
  
             //instructions: comment out other block
  
             yield return 0;
             Debug.Log("Hello");            //prints once
             //Debug.Log("Hello " + i);    //prints 5 times
         }
     }
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

1 Reply

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

Answer by SirCrazyNugget · Jul 04, 2014 at 04:39 AM

The good news is your code works perfectly, the bad news is you're about to kick yourself. (I think anyway)

In the console you have an option to "Collapse" repeated items. I'm guessing you've got that on so only seeing repeated "Hello"'s only once though they have a counter on the right as to the number of times they've appeared. With the other lines with the appended i's as the comments are unique they're individually listed.

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 nastajus · Jul 04, 2014 at 04:47 PM 1
Share

PEB$$anonymous$$AC. sigh. I didn't see the little counter that accumulates all the identical messages. There's 92 hello's compounded in the image I posted on my github. I finally just noticed the little compound counter on the right side of the hello line. Thank you!

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

2 People are following this question.

avatar image avatar image

Related Questions

Coroutine Won't Stop Using IEnumerator 1 Answer

Loop Coroutine For A Demo Mode 1 Answer

Can I run multiple instances of the same coroutine in parallel? 1 Answer

I can't start a coroutine. I get a weird message from visual studio 1 Answer

move inside a coroutine 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