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 Siflou · Oct 27, 2013 at 06:18 AM · coroutinestop

Coroutine exiting unexpected

Hey Guys,

So here is my problem. I have a coroutine which is stopped, without even being completed, I wonder is some one has an issue with this. It isnt stopped because there is only 1 StopCoroutine call in my entire project and it is not stopping the problematic function. Also it is not the one calling the coroutine which is the problem because it is a singleton so it is never destroyed. Wonder if some of you might have encountered this issue. Here is the code of my coroutine.

 IEnumerator MoveTroops(BaseCell aSource, BaseCell aTarget, Troops aTroops, float aTime)
     {
         float lerpTime = 0;
         bool mLabelAnimPlayed = false;
         Link link = aSource.GetLink(aTarget);
         Vector3 troopsStartPos = Vector3.zero;
         Vector3 troopsEndPos = Vector3.zero;
         Vector3 startPos = Vector3.zero;
         Vector3 endPos = Vector3.zero;
         
         //
         while(lerpTime < aTime)
         {
             if(link == null)
             {
                 yield break;
             }
             
             //
             lerpTime += Time.deltaTime*PlayerData.Instance.MovementSpeed;
             link.Value = lerpTime/aTime;
             
             //
             troopsStartPos.Set(aSource.transform.position.x, aSource.transform.position.y, -2);
             troopsEndPos.Set(aTarget.transform.position.x, aTarget.transform.position.y, -2);
             aTroops.transform.position = Vector3.Lerp(troopsStartPos, troopsEndPos, lerpTime/aTime);
             
             //
             if((aTarget.Owner != PlayerData.Instance.Owner) && (aTarget.CurrentState == ECellState.Idle))
             {
                 if(lerpTime > (0.5f*aTime) && !mLabelAnimPlayed)
                 {
                     startPos.Set(aTroops.transform.position.x, aTroops.transform.position.y, 0);
                     endPos.Set(aTarget.transform.position.x, aTarget.transform.position.y, 0);
                     float dist = Vector2.Distance(startPos,endPos);
                     
                     if(dist <= START_FIGHT_MODE_DISTANCE)
                     {
                         aTarget.MoveLabelUp();
                         mLabelAnimPlayed = true;
                     }
                 }
             }
             
             Debug.Log("GOING TO"+lerpTime);
             yield return new WaitForEndOfFrame();
             Debug.Log("Coming BACK"+lerpTime+ " < "+aTime);
         }
         
         //
         if(aTarget.Owner == PlayerData.Instance.Owner)
         {
             aTarget.NumberOfTroops += aTroops.Count;
             aTarget.RemoveTroop(aTroops);
         }
         else
         {
             //TODO: Check if its me who's attacking.
             if(aTarget.CurrentState == ECellState.Idle)
             {
                 StartCoroutine(Fight(aSource, aTarget, aTroops));
             }
             
             //
             aTarget.AddTroops(aTroops);
         }
         
         Debug.Log("ending");
     }

The debug "ending" never gets call and the "coming back" debug shows that the condition is still true so it should continue, but it seems to stops for no reason. Any ideas ?

Thanks a lot for your time !

Claude

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 Siflou · Oct 29, 2013 at 12:12 AM 0
Share

Yes you are right, this was it, I was too tired after a entire day of program$$anonymous$$g and couldn't see it. Good catch my friend :)

avatar image karlhulme · Oct 30, 2013 at 09:31 AM 0
Share

Thanks for taking the time to mark it as the answer - that really made my day yesterday!

1 Reply

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by karlhulme · Oct 27, 2013 at 07:32 AM

Is it possible for 'link' to become equal to null while the coroutine is running. This would explain the debug output you're seeing as you have a yield break on that condition.

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

16 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

Related Questions

How to stop coroutines or functions 2 Answers

How to Stop C# Coroutine 2 Answers

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

[SOLVED] Is StopAllCoroutines stopsing itself? 2 Answers

StartCoroutine of a child object using String 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