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 yeagz7 · Dec 03, 2014 at 10:08 PM · coroutinenot workingcoroutinesienumeratormethod

StopCoroutine with IEnumerator not working

So Unity just added functionality to stop coroutines with an IEnumerator instead of just a string. However it is not working for me. Has anyone else had this issue?

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 MapuHoB · Mar 18, 2015 at 01:45 PM 0
Share

@yeagz7 do you still have this problem? Did you find any way to fix it? I'm currently in the same situation.

2 Replies

· Add your reply
  • Sort: 
avatar image
4

Answer by jenci1990 · Dec 03, 2014 at 11:17 PM

It's works, if you start the corutine with string:

 public class Test : MonoBehaviour {
     void Start() {
         StartCoroutine("Printer", "ds"); //Use string for method name
     }
 
     void Update() {
         if (Input.GetKeyDown(KeyCode.A)) {
             StopCoroutine("Printer");
         }
     }
     
     IEnumerator Printer(string _test) {
         float f = 1;
         while (f > 0f) {
             Debug.Log(_test);
             yield return new WaitForEndOfFrame();
         }
         yield return false;
     }
 }
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 yeagz7 · Dec 03, 2014 at 11:27 PM 0
Share

I know you can stop the coroutine with a string but in 4.6 they added functionality to stop it with the method signature. So:

 public class Test : $$anonymous$$onoBehaviour {
          void Start() {
              StartCoroutine(Printer(), "ds"); //Use string for method name
          }
      
          void Update() {
              if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A)) {
                  StopCoroutine(Printer());
              }
          }
          
          IEnumerator Printer(string _test) {
              float f = 1;
              while (f > 0f) {
                  Debug.Log(_test);
                  yield return new WaitForEndOfFrame();
              }
              yield return false;
          }
      }

I'm not getting any errors. The coroutine is just not stopping.

avatar image jenci1990 · Dec 03, 2014 at 11:53 PM 3
Share

It's worked, but i don't like it:

 public class Test : $$anonymous$$onoBehaviour {
     public Coroutine coroutine;
 
     void Start() {
         coroutine = StartCoroutine("Printer", "ds");
     }
 
     void Update() {
         if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.A)) {
             StopCoroutine(coroutine);
         }
     }
     
     IEnumerator Printer(string _test) {
         float f = 1;
         while (f > 0f) {
             Debug.Log(_test);
             yield return new WaitForEndOfFrame();
         }
         yield return false;
     }
 }
avatar image SNS_Case · Jun 09, 2015 at 10:56 PM 0
Share

It makes sense though, you could think of a coroutine as being an instance when it's launched. The engine would have no idea which coroutine is being referenced as many could exist simultaneously, unless you pass the exact instance you want to stop. It's possible that when started/stopped as a string, only one instance can exist, I'm not sure.

avatar image
1

Answer by honor0102 · Apr 26, 2020 at 09:14 PM

checkout huacanacha's answer at :

https://answers.unity.com/questions/934490/stopcoroutine-is-not-stopping-my-coroutines.html

according to that answer:

In more recent versions of Unity (at least 5.3 onwards) you can keep a reference to the IEnumerator or returned Coroutine object and start and stop that directly, rather than use the method name. These are preferred over using the method name as they are type safe and more performant. See the StopCoroutine docs for details.

  Coroutine lastRoutine = null;
   
  lastRoutine = StartCoroutine(YourCoroutine());
   
   // [ ... ]
   StopCoroutine(lastRoutine);



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

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

Coroutines not passing yield 1 Answer

Collection Change During Iteration 0 Answers

Backspace typewriter effect 1 Answer

Make a function that can return string or IEnumerator 2 Answers

Coroutine Not Working 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