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 trs9556 · Sep 15, 2013 at 11:17 PM · coroutineyieldienumeratoryield waitforsecondsbreak

WaitForSeconds is breaking out of my IEnumerator

I don't understand how this is possible but hear me out - when this IEnumerator is called:

     [EDIT] method removed for security reasons.


All I get printed out in the console is "go1". I waited for over 2 minutes to see if anything else would be printed out.

Now if I comment out line 3 (yield return new WaitForSeconds(1.25f);) so that the yield doesn't get executed all my code is executed all the way down to the "whattt" being printed out in my console.

Why/how is it possible that the yield is breaking my coroutine. I've used tons of yields why is this one specifically ruining my code?

Comment
Add comment · Show 2
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 trs9556 · Sep 15, 2013 at 11:23 PM 0
Share

Just did a test, I replaced line 3 with yield return null; and my code worked. Once again something about the WaitForSeconds part is killing my code

avatar image Bunny83 · Sep 15, 2013 at 11:32 PM 0
Share

Are you sure you don't have any additional code that could affect the coroutine? For example something that destroys the gameobject or the script which runs the coroutine? Without more information we can't say much about your problem. Generator functions are a language feature of C# so there's no issure there. The Unity coroutine scheduler also has a quite well defined behaviour. So it has to be something you do to the coroutine / gameobject / script.

1 Reply

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

Answer by trs9556 · Sep 15, 2013 at 11:33 PM

Like always there is a valid explanation.

What I did not know is WaitForSeconds is influenced by Time.timescale. I was setting my timescale to 0 therefore my waitforseconds was being held up.

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 JChilton · May 01, 2014 at 09:57 PM 0
Share

Another item to keep note of, is that if the monobehaviour the coroutine was started becomes disabled, the coroutine will also stop. Although it doesn't apply here it's possible you may come across it in the future.

You can also make your timescale independent wait using Time.realtimeSinceStartup,

 float startTime = Time.realtimeSinceStartup;
 float waitTime = 3; //wait 3 seconds
 while(Time.realtimeSinceStartup < startTime + waitTime) yield return null;

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

Coroutoutine doesnt work properly. 3 Answers

Please help with While Loops 1 Answer

Update() can not be a coroutine. 2 Answers

Custom Yield Instruction for FixedUpdate frames 3 Answers

[ Coroutine: Move Next ] CPU usage 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