Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Oct 22, 2019 at 02:29 PM by tormentoarmagedoom for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by tormentoarmagedoom · Oct 21, 2019 at 01:18 PM · coroutinestop

[SOLVED] Is StopAllCoroutines stopsing itself?

Hello there!

I have this simple question. If you execute this: what will happen? Because i debbug it and it seems it continue executing, but it nere restarts, can someone explain me how it works a little better?

 IEnumerator Deambular()
     {
         StopAllCoroutines();
         if (something) // THINGS A
         else 
         {
           // THINGS B
          yield return new WaitForSeconds(3));
          StartCoroutine(Deambular());
         }
     }

I wil never restart itself due that StopAllCoroutines, right=? Or What ?

Thanks in advance

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

  • Sort: 
avatar image
4
Best Answer

Answer by TreyH · Oct 21, 2019 at 02:20 PM

Basically StopAllCoroutines will kill any instructions that are suspended by a yield instruction. In the simplest case:

 IEnumerator Deambular ()
 {
     StopAllCoroutines ();
     Debug.Log("BEFORE YIELD");
     yield return null;
     Debug.Log("AFTER YIELD");
 }


will only print "BEFORE YIELD".

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 tormentoarmagedoom · Oct 22, 2019 at 09:02 AM 0
Share

Thanks for answer, so what i say in the other answer comment is true?

avatar image TreyH tormentoarmagedoom · Oct 22, 2019 at 10:58 AM 1
Share

Yeah, both will print since your StartCoroutine call adds a new coroutine to your $$anonymous$$onoBehaviour right after you clear the others. In the same way, doing that from within the Deambular() function would cause a stack overflow.

avatar image tormentoarmagedoom TreyH · Oct 22, 2019 at 02:28 PM 0
Share

Just onle last qeustion. I posted it here

https://answers.unity.com/questions/1673561/stopallcoroutines-stops-coroutines-in-other-script.html

Thanks!

avatar image
3

Answer by misher · Oct 21, 2019 at 02:13 PM

You should not call StapAllCoroutines() inside a coroutine. Do it before, it will stop all coroutines, theb if you start another one it will not be affected. If you want to stop a coroutine from inside, you can use yield break instead

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 tormentoarmagedoom · Oct 22, 2019 at 09:03 AM 0
Share

I see, then, if do this this:

  StopAllCoroutines ();
  StartCoroutine(  Deambular () );

 IEnumerator Deambular ()
  {
      Debug.Log("BEFORE YIELD");
      yield return null;
      Debug.Log("AFTER YIELD");
  }


will print both sentences?

Thanks for your time guys!

avatar image tormentoarmagedoom · Oct 22, 2019 at 02:28 PM 0
Share

Just onle last qeustion. I posted it here

https://answers.unity.com/questions/1673561/stopallcoroutines-stops-coroutines-in-other-script.html

Thanks!

Follow this Question

Answers Answers and Comments

121 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 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 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 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 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

How to stop coroutines or functions 2 Answers

Coroutine exiting unexpected 1 Answer

How to Stop C# Coroutine 2 Answers

StopAllCoroutines() stops coroutines in other scripts? -- Other behaviours ?? 1 Answer

What will StopCoroutine exactly do? 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