Search Unity

Coroutines as member functions

Discussion in 'Scripting' started by andrewc, Sep 1, 2009.

  1. andrewc

    andrewc

    Joined:
    Aug 20, 2008
    Posts:
    180
    I have an object with a member function. However if I put a Yield statement into that member function and run it using the dot operator (a.run()) the function doesn't work. The part of the function before the yield doesn't even seem to get evaluated. Does anybody know why this is.

    Thank You
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Coroutines (in C# at very least) are started through StartCoroutine.
     
  3. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Yes, in C# you must use StartCoroutine() to call any coroutine. I filed a bug a while ago about coroutines silently failing when called directly, but it's quite possible that there's no reasonable way for the compiler to identify coroutines without getting false positives.