Skip to main content
edited title
Link
House
  • 73.5k
  • 17
  • 188
  • 276

Hi, doubts about How to track if an action is executing with IEnumerator and StartCoroutine

Source Link
JamesB
  • 279
  • 4
  • 15

Hi, doubts about IEnumerator and StartCoroutine

My code:

public class CharacterBehaviour: MonoBehaviour {

bool isExecuting=false;
Action action;

void Start{
action=new Action();
}

void Update{
//Other methods
if(!isExecuting)
{
StartCoroutine(action.execute(out isExecuting));
}
}    

public class Action: MonoBehaviour
{
IEnumerator execute(out isExecuting)
{
return YieldReturnNull)();

//Execution

isExecuting=false;
}


public IEnumerator YieldReturnNull()
{
yield return null;
}
}

I am using IEnumerator to start a coroutine right? But I need this out value to do not start a lot of coroutines in Update, just when it finalizes I must start another. The problem it's that I need to return of yield of course in the beggining (The YieldReturnNull method is a trick because IEnumerator does not accept out or ref as parameter in a method returning yield) but it returns for me this error:

The out parameter `isExecuting' must be assigned to before control leaves the current method.

How to solve it? I need to return yield in the beggining and apply the bool in the end. Thanks. :)