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 /
avatar image
0
Question by Thomas-Hawk · Jun 25, 2018 at 06:04 AM · coroutineienumeratorstartcoroutineiterategarbage collection

Can I use StartCoroutine inside of the same coroutine with a new variable?

I have a couroutine which takes a class of mine, "Wire", as a parameter.

This coroutine, changes a boolean state on this wire class, and then calls the same coroutine on the 1-5 other wires stored in its class instance as a list to also change their state (if, of course, they need to be changed, to avoid an infinite back-and-forth loop)....which then of course calls the same coroutine passing those, etc etc.

Does this count as garbage? Is there a way to trigger that coroutine without it being nested? Am I correct to say that, this means, the coroutine called on the first wire is not stopping until the last wire in the chain's coroutine stops?

alt text

Here is the coroutine in question. "pulser" is just taking a single reference to a single wire object, and calling this coroutine, passing that wire....that wire, in this snapshot of the profiler, is connected to a line of other wires.

     public IEnumerator RefreshOneSimple(WireNode theNode){

         WireNode temp;
 
         //For every wire this one is connected to,
         foreach (Behaviour conn in theNode.ports) {
             if (conn != null) {
                 if (conn.name.Contains ("WireNode")) {
                     temp = conn as WireNode;
                     if (temp.state != theNode.state) {
                         //If it is not the same state as this one, change that now.
                         temp.state = theNode.state;
                         foreach (LineRenderer cable in theNode.wirelines) {
                             if (theNode.state == true)
                                 cable.materials [0].color = theNode.onColor;
                             if (theNode.state == false)
                                 cable.materials [0].color = theNode.offColor;
 
                         }
                         foreach (LineRenderer cable in temp.wirelines) {
                             if (temp.state == true)
                                 cable.materials [0].color = theNode.onColor;
                             if (temp.state == false)
                                 cable.materials [0].color = theNode.offColor;
 
                         }
                         //yield return null;
                         StartCoroutine (RefreshOneSimple (temp));
                         yield return null;
                     }
 
 
                     //Now do the same thing with each one of those, and then let the next frame happen. 
 
                 }
 

                 if (conn.name.Contains ("Powerable")) {
                     //print ("Doing powerable in enum");
                     Powerable p = conn as Powerable;
                     p.powered = theNode.state;

                     p.StartRefresh ();
                     yield return null;
 
 
                 }
 
             } else {

             }
         }
 

         yield return null;
     }


EDIT: I thought, well, if instead of calling this routine inside of itself, I could call a new routine which simply starts the original routine with the new variable, then once that new "StartCoroutine" exits, the first one can disappear.

But, this resulted in, only my first wire updating. So I reverted.

Edit: In case I am not clear, I only need any of this to happen when a wire has its state changed. I.e., during the moment a lever is switched.

coroo.png (46.2 kB)
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

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

93 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

Related Questions

Item duration doesn't stack 3 Answers

Return result of the IEnumerator. 2 Answers

Coroutines IEnumerator not working as expected 2 Answers

How to pass "ref parameter" in iterator method? 1 Answer

I can't start a coroutine. I get a weird message from visual studio 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