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 shahprateek317 · Apr 07, 2021 at 01:54 PM · coroutinesnested

Coroutine stops after any yield statement halfway through

Hi - I have a coroutine that calls several other coroutines in sequence. So far I have been quite successful at using nested coroutines to sequence certain animations, etc., but this particular one has been causing me trouble for a while. The (simplified) coroutine is as follows:

 public IEnumerator UnitDeploy(UnitCardView deployed, UnitView target) 
 {
         // Multiple yield returns before this which function fine
         UnitView deployView = RowView.DeployedUnit; 
         RowView.DeployedUnit = null;
         Debug.Log($"{deployView} {deployView.MyUnit}"); 
         // prints a non-null MonoBehaviour class name for deployView
 
         if (target == null) {
             Debug.Log("Starting playdeploy coroutine"); // prints this
             yield return deployView.PlayDeploy();
             Debug.Log("Started deploy animation"); // does not print this
             deployCard.ActionPrimary(null);
         } else {
             Debug.Log("Has target - playing secondary cast"); // prints this
             deployCard.ActionPrimary(target.MyUnit);
             StartCoroutine(deployView.PlayCast(true));
             yield return deployView.AnimateSecondary(target, deployCard);
             Debug.Log("Done playing deploy secondary animation"); // does not print this
        }
 }


PlayDeploy() and AnimateSecondary() are both coroutines to which I've added a Debug.Log as the final line - this line also always prints. I don't understand how it's possible that the last line of the called coroutine executes but not the next one in the caller? yield return AnimateSecondary() is called from other coroutines in this file and works fine, so I'm pretty sure the issue is somewhere in this method...

Adding the PlayCast() code as requested... but this, too, is called from other places and works fine from there.

 public virtual IEnumerator PlayCast(bool secondary) {
             GameObject muzzlePrefab = ... // gets a file from Resources
             AudioClip muzzleSound = ... // gets a file from Resources
     
             yield return PlayVFX(muzzlePrefab, muzzleSound); // plays these files - executes correctly
 }

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 logicandchaos · Apr 07, 2021 at 02:35 PM 0
Share

debug the values of target and deployCard, also you should post deployView.PlayCast()

avatar image shahprateek317 logicandchaos · Apr 07, 2021 at 03:15 PM 0
Share

Hi - thanks for the feedback - adding the playcast() code but again, it is called from multiple places and works fine.

I am checking target earlier in the method - it is sometimes null and sometimes not, as expected. But in both cases the yield returns stop the coroutine.

I've even tried to set a bool at the end of PlayDeploy() and AnimateSecondary() and change the caller code to e.g. a startcoroutine(PlayDeploy()) followed by a yield return new WaitUntil(() => boolName) but even this does not work, despite the bool getting set... so it seems after a point yield statements simply kill this caller coroutine?

0 Replies

· Add your reply
  • Sort: 

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

117 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

Related Questions

Nested coroutine handling 0 Answers

Problems with nested coroutines: while loop freezes 1 Answer

Error with nested coroutines 0 Answers

Lerp in Nested Coroutines doesn't work if I add some functions inside the Coroutines 1 Answer

Time Manager Class Implementation Like Coroutine in Unity 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