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 MapuHoB · Dec 31, 2014 at 05:42 AM · c#coroutinemethod

StopCourutine not working as expectedd

 private IEnumerator Move()
     {
         while (!RunGameScript.Instance.IsGameRunning)
         {
             yield return null;
         }
         
         yield return new WaitForEndOfFrame();
         this.SetDirectionBeginning();        
 
         while (true)
         {
             if (RunGameScript.GameOver)
             {
                 StopCoroutine(this.Move());
             }
             else if (this.HasReachedLimit)
             {                
                 this.SetDirection();
             }
 
             yield return null;
         }
     }


The problem is that it enters million times in the GameOver if and I don't want to paste this if in the update. Any idea why this doesn't prevent the move method from invoking? I tried also to use StopCouroutine with string but still didn't work.

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 iwaldrop · Dec 31, 2014 at 06:43 AM

As far as I know, this is the easiest way to exit a coroutine.

 yield break;
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 MapuHoB · Dec 31, 2014 at 06:56 AM 0
Share

http://prntscr.com/5mwn4a I get this error when I try it. Is it even possible to return break?

avatar image iwaldrop · Dec 31, 2014 at 06:58 AM 0
Share

Doh! Updated answer.

avatar image MapuHoB · Dec 31, 2014 at 06:59 AM 0
Share

Thanks! Unexpectedly easy :))

avatar image
1

Answer by Thom Denick · Dec 31, 2014 at 06:01 AM

StopCoroutine doesn't work like that. You want to just:

StopCoroutine("Move");

or

 // variable that holds reference to coroutine (IEnumerator)
 public IEnumerator routine;
  
 // get IEnumerator from Coroutine and start
 routine = DoWork();
 StartCoroutine( routine );
  
 // stop Coroutine
 StopCoroutine( routine );

From here: http://forum.unity3d.com/threads/how-to-use-the-new-stopcoroutine-ienumerator.249732/

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 MapuHoB · Dec 31, 2014 at 06:13 AM 0
Share

http://pastebin.com/ftfxEQSY - is this the way I am supposed to do it in my case?

avatar image iwaldrop · Dec 31, 2014 at 06:41 AM 0
Share

I hope "StopCourutine" (pastebin) is a copy paste error.

avatar image MapuHoB · Dec 31, 2014 at 06:58 AM 0
Share

Yeah it is I just wrote in at pastebin itself not in the editor there might be some other mistakes like this, but still is this the way to achieve the expected results?

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

27 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

Related Questions

Audio mixer Setfloat() method problem in coroutine 0 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Code with Coroutine not working as intended. 2 Answers

why am i getting this error?(not all code paths return a value) 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