I’m not a stranger to async programming, but I hit a point where I am having a hard time intuiting how the logic flows in this one.
So in the new FadeOut function:
- Check if there is a coroutine running. If there is, stop it.
- Set the active coroutine to fade out
- yield return the current coroutine
That all makes sense. What doesn’t make sense is what happens when the unity back end goes through and continues the coroutines. We’ve returned a coroutine, but FadeOut was itself a coroutine that was called by the scene management somewhere. If I’m interpreting this right, on the second pass, since we returned a coroutine, will the logic just jump straight into the coroutine we returned? If that’s true, why does the FadeOutRoutine keep getting called when we yield return null? Does the coroutine only end when we don’t yield anything?