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 Goldseeker · Jun 09, 2014 at 09:20 PM · bugcoroutine4.5

Coroutines Bug? Unity 4.5

So the situation is i have two monobehaviours(object1 and object2) object1 is running coroutine that waits for coroutine running on object2 and the problem is that when i call object2.StopAllCoroutine() object2 coroutine stops, but coroutine on object 1 does not resume

Example:

     public class RootObject: MonoBehaviour
         {
             private CoroutineHost coroutineHost;
             public void Start()
             {
                 var go = new GameObject();
                 coroutineHost = go.AddComponent<CoroutineHost>();
                 
                 
                 this.StartCoroutine(GamePlayRoutine());
                 this.StartCoroutine(StopAllCoroutinesRoutine());
             }
     
             public IContained<IGameplay> gameplay
             {
                 get;
                 set;
             }
     
             private IEnumerator GamePlayRoutine()
             {
                 yield return coroutineHost.StartCoroutine(gameplay.contained.Run());
                 Debug.Log("!!!!");
                 gameplay.Dispose();
             }
     
             private IEnumerator StopAllCoroutinesRoutine()
             {
                 yield return new WaitForSeconds(1.0f);
                 Debug.Log("Killing Coroutines");
                 coroutineHost.StopAllCoroutines();
             }
         }

In this example only Killing Coroutines is being printed, but never "!!!!"

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 Tarlius · Jun 10, 2014 at 08:48 AM

I don't think its a bug, its probably a design decision.

If you force quit a program, do you expect it to (or it to be in a fit state to) return a value to its caller?

Its an odd case though!

I think to solve your problem you will want to make something like a EndGame method which will set a flag to let the coroutine end itself correctly, or just not nest the coroutine in the first place.

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 Goldseeker · Jun 10, 2014 at 09:03 AM 0
Share

I don't agree with analogy about quitting program, as i am not trying to get return value of ter$$anonymous$$ated program, but just tracking if the program has ter$$anonymous$$ated.

But i can now agree that it is probably not a bug as it is the case in all the other unity versions

avatar image Tarlius · Jun 10, 2014 at 11:54 AM 0
Share

Since coroutines are really just IEnumerators, I think the analogy is more valid than you might think at first. I do wonder about the implementation though and do agree that it feels like you are "tracking" it.

avatar image Goldseeker · Jun 10, 2014 at 03:11 PM 0
Share

I'm well aware that coroutines are just on which Unity call $$anonymous$$oveNext every frame(except for specific yield instructions)

But i'm still sure that the sematics of yield return on Coroutine is to wait for the other coroutine to be finished, and after i stop the coroutine by using StopAllCoroutines coroutine really is finished.

This situation leads to a lot of problems(leaving coroutine hanging indefinetly is in the best case a memory leak) that are rendering this function useless in my opinion

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

22 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

Related Questions

Coroutines Cannot be Stopped Outside Initiating class 1 Answer

New Unity 4.5 Transform Organization Bug? 0 Answers

Unity stops rendering 2 Answers

Odd behavior changing another script's variable via coroutine 0 Answers

Line of code skips randomly at times? 1 Answer


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