Hello,
I am running a coroutine and I want it to exit early if an error happens. However it doesn’t seem to work… Here is an example:
void Start()
{
StartCoroutine( Foo() );
}
IEnumerator Foo()
{
// do something
yield return new WaitForSeconds( 1 );
// do something else
yield return new WaitForSeconds( 1 );
if( errorHappened )
{
yield return 0;
}
// error has not happened so move on
...
// do something else
yield return new WaitForSeconds( 1 );
// done
yield return 0;
}
In this example when errorHappened is true the coroutine will yield and then continue its execution as if nothing happened…
Does this mean that the only way to exit a coroutine early is to call StopCoroutine ?
Thank you