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 /
  • Help Room /
avatar image
0
Question by Capoymaster · Jul 28, 2016 at 01:14 PM · coroutineloopyield

Coroutines Madness ();

Hello folks, I've come with coroutines madness:

First Question is Understanding WHY the MainCheckRoutine() is executed twice......

 private bool ready;
       private float customTime; 
     
      void Awake()
         {
                    ready = false;
                 }
     void  Start () {       
             customTime = 0.8f;
             StartCoroutine( ELbuscon());
                       }
     
     void Update()
         {
             customTime -= Time.deltaTime;
             if (customTime < 0)
             {
                 if (ready == false)
                 {
                     GameObject[] fs = GameObject.FindGameObjectsWithTag("litrick");
                     GameObject[] ts = GameObject.FindGameObjectsWithTag("estrello");
                     GameObject[] rs = GameObject.FindGameObjectsWithTag("match");
     
                     if (fs.Length > 0 || ts.Length > 0 || rs.Length >0)
                     {
                                                 //nothing
                     }
                     else
                     {
                       ready = true;
                     }
                 }
             }
         }
     
     IEnumerator ELbuscon()
         {
             while(ready == false)
             {
                 yield return new WaitForFixedUpdate();
                }
            
                 MainCheckRoutine();
         }
     void MainCheckRoutine(){
     Debug.Log("why am i exectude twice?"); 
 SomeCheckingThingFunc();
 FinalStep();
     }
 void FinalStep(){
 if(something==else){
 StartCoroutine(Elbuscon());}
 // THIS Freezes out everything
 }

The fact is that if i swtich Start function to IEnumerator Start(){}. and i make some yield inside.... the code just runs once....... makes no sense on me because even Coroutines play independient its supose to yield the instructions after ready = true is met....... Just once becouse Start is fired once... dont understand yah! :(_

Second Question is about looping and freezing. Which would be the best approach to loop the Elbuscon() function after a requirements on the very end of this fucntion; like FinalStep(); this way seems to freeze unityeditor couse a infinite loop even it's not.(my guess...)

Thank You !

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

Answer by Bunny83 · Jul 28, 2016 at 01:19 PM

Well, you have an infinite chain of method calls. The reason is that your "ready" variable is true when "ELbuscon" runs "MainCheckRoutine". MainCheckRoutine will call FinalStep and final step immediately runs a new "ELbuscon" coroutine. However since ready is still true the coroutine immediately calls "MainCheckRoutine" again, endlessly.

So you're caught in an infinite recursive function call chain. which eventually would cause a stackoverflow. However since each coroutine also allocates memory it might take a while. Maybe you would even run out of memory first ^^.

Comment
Add comment · Show 1 · 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 Capoymaster · Jul 28, 2016 at 02:26 PM 0
Share

Yes, Thats for the second question, when FinalStep() runs it goes infinite loop.... i was asking for the approach to get that. And for the First question, Figure it FinalStep() is erased........ it still runs $$anonymous$$ainCheckRoutine() 2 times even after the while statement it should be only fired ONC$$anonymous$$.. Any clues?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

What to do for many comparison operations in foreach loop? 0 Answers

Nothing after coroutine gets executed 1 Answer

[C#] How to write a generic yield return WaitForCondition with an expression as argument ? 3 Answers

Round Loop Problem?... 1 Answer

IEnumerator skips remaining function after yield 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