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 musashi255 · Dec 07, 2017 at 03:09 AM · arraycoroutinearrayscoroutinescoroutine errors

Array reference being changed without me knowing, or, When a coroutine is run on a monobehavior and then stopped with StopCoroutine (coroutine) it stops the same coroutine being run on another instance of the same monobehavior on a different object.

[Edit] Turned out to be an issue with an array reference appearing to be changed to a different one, when it was actually the same array still having references passed around.

I am starting the coroutines separately on each gameobject and the code within the coroutine is supposed to be stopping the coroutine stored in a field in that instance of the monobehavior (itself).

I know this is happening because i am debug logging the name of the gameobject from within the coroutine and it is correctly showing two running at once from different objects, but then both coroutines stop when one is supposed to, leaving the first coroutine unfinished.

is this intended behavior? do i really have to somehow manage an array of coroutine references to have the same one run multiple times simultaneously?

Just tried storing the coroutine like coroutine = StartCoroutine (Coroutine ()) and then stopping coroutine. still stops them both??? Why?

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 musashi255 · Dec 07, 2017 at 03:56 AM

[actual answer] It was a problem with array references being passed around and never cleared. i was using the same array that other classes had references to when i though i was passing a different array. Not the first time i did this to myself : | I will try to adjust the question and tags so it will be found by others having the same problem but not regarding coroutines.


[2nd edit] it is starting to look like this is an issue with a class i wrote to hold data, which is not serializable. in this class i have an array of references to the same type of class which is used temporarily to iterate through and do things. it seems when i change the array for a new one, that other instances of that class are also changed. I am checking this class and the array within it throughout the process of the coroutine, and although the reference to the class does not change, the array within the class is changing even though... wait ................ ok while writing this i figured it out and fixed it. answer above.


[Edit] No, actually the below wasn't true, good thing i didn't accept that answer! going to resort to not storing the coroutine at all and creating a new one each call like StartCoroutine (Coroutine ()), and if performance is an issue which i doubt in this case, i will have to have an array of IEnumerators to start and stop separately.... very inconvenient, i would think each mono should start and stop it's own coroutines independently.


[original incorrect answer]Turns out I was setting the reference to the wrong object and thus the monos that were supposed to still have coroutines running on them were simply no longer the target for that coroutine.

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

121 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 avatar image avatar image avatar image avatar image

Related Questions

Trouble with coroutine 0 Answers

Coroutine Not working properly. 1 Answer

c# Coroutines and Waypoints HELP PLS!!!,C# Coroutine and Waypoints Help pls!!! 2 Answers

Need help using coroutines 1 Answer

Unity C# Punching Coroutine not completing 0 Answers


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