Search Unity

New added StopCoroutine(Coroutine coroutine) override function causes errors.

Discussion in 'Editor & General Support' started by xVergilx, Dec 25, 2014.

  1. wooli

    wooli

    Joined:
    Aug 7, 2015
    Posts:
    1
    Guys, I've had this issue as well but I resolved it. Posting to see if this will help others.

    TLDR. Make sure to use the StopCoroutine method on the class(instance) that contains the actual coroutine.

    For me.
    StopCoroutine(action.coroutineReference); // caused an error (but still worked)

    action.StopCoroutine(action.coroutineReference); // has no error messages

    Where action is my other class that contained the coroutine.

    *Story time*
    In my situation, my Coroutine is stored in a seperate script (inside an 'Action' class). Because coroutines is a monobehaviour I had to do the whole gameObject.addcomponent to add it to my component instead of declaring a new class, and then I'd call a function which starts the coroutine in that class.

    I tried to use StopCoroutine on my main gameObject, which 'worked' but produced that error.
    To fix it, i just used the StopCoroutine method from within the action class, and the error message is gone. I believe it has something to do with mixing up order of operations when you have one command to 'stop coroutine' in one object, while the actual coroutine exists in another object.
     
    Aksoq and Disastercake like this.
  2. rocker182

    rocker182

    Joined:
    Jun 3, 2016
    Posts:
    3
    i was having the same bug But then i fixed it using this syntax
    Code (CSharp):
    1. StartCoroutine (StartGettingData());
    2. StopCoroutine ("StartGettingData");
    This seemes to stop the annoying error message in consol
    i was using
    Code (CSharp):
    1. IEnumerator StartGettingData () {
    2. .
    3. .
    4. .
    5. .
    6. yield return www1;
    7. }
     
  3. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I have this error on 5.3 and 5.4 .. It doesn't matter if I use string to stop coroutine. No error if I do StopAllcoroutine.
     
    huangjizhong and JohnTube like this.
  4. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Still getting this after 5.3.4 and 5.4 beta 18
     
  5. huangjizhong

    huangjizhong

    Joined:
    Sep 13, 2016
    Posts:
    1
    Hi,do you solve this problem? It is annoying me!
     
  6. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    Nope. Not solved.
     
  7. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    How are you starting/stopping the coroutine?

    This causes no errors:

    Code (csharp):
    1. var coroutine = StartCoroutine(SomeRoutine());
    2. ...
    3. StopCoroutine(coroutine);
     
  8. castor76

    castor76

    Joined:
    Dec 5, 2011
    Posts:
    2,517
    I have tried that too... it seems to be unclear on what actually triggers it.

    I have tried all 3 of them. StopAllCoroutine. Stop using string name , stop using the method above.
     
  9. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    15,620
    I'm seeing this too on my laptop, Unity 5.5.0f3. I wasn't seeing it last night on my desktop.
     
  10. jonc113

    jonc113

    Joined:
    Mar 10, 2013
    Posts:
    22
    I am using Unity 2017.1 and was getting the error. I got rid of it by following advice: used IEnumerator instead of Coroutine and put my StopCoroutine code in the same class that has the routine I'm stopping.

    So far, so good!
     
  11. IgorAherne

    IgorAherne

    Joined:
    May 15, 2013
    Posts:
    393
    I think it triggers when you do
    Code (CSharp):
    1. Coroutine c = _myOtherMonobehavior.StartCoroutine(MyCoroutine());
    2. this.StopCoroutine(c);

    Just got it in 2018.2.0f2
     
    Leohoran likes this.
  12. xVergilx

    xVergilx

    Joined:
    Dec 22, 2014
    Posts:
    3,296
    This a really necro-necro post.

    Also, you're stopping coroutine that runs on the other behaviour, which you shouldn't do.
    Hence StopCoroutine is actually checks if coroutine is running on the specific behaviour, not all of them.

    If you wish to stop the coroutine created that way, make sure to call StopCoroutine on the same behaviour it was created on. E.g.:
    Code (CSharp):
    1. _myOtherMonoBehaviour.StopCoroutine(c);
     
    HofiOne likes this.
  13. DenisWASD

    DenisWASD

    Joined:
    Dec 10, 2016
    Posts:
    9
    Have this issue when using:
    Code (CSharp):
    1. if(workC != null)
    2.         StopCoroutine(workC);
    (2019.1.14f1)
     
    IgorAherne likes this.
  14. anurag13june2001

    anurag13june2001

    Joined:
    Apr 19, 2021
    Posts:
    1
    Jackal256 and LilGames like this.