Doing a “yield return null” inside a while-loop of a coroutine never returns. It enters the first while-loop iteration, but then never continues after the yield.The problem exists in the editor and player.
Please consider the following coroutine code (copied from Loading.cs):
Debug.Log("#1");
// Fade out
Time.timeScale = 0;
while (transition.alpha < 1)
{
transition.alpha += Time.unscaledDeltaTime * invDuration;
AudioListener.volume = Mathf.Clamp01(1 - transition.alpha);
Debug.LogFormat("#1: while ({0} < 1)", transition.alpha);
yield return null;
}
AudioListener.volume = 0;
Debug.Log("#2");
Running this code in Unity 5.5.2p4 outputs the following text to the Console window:
#1
#1: while (0.01929984 < 1)
#1: while (0.3549189 < 1)
...
#1: while (1 < 1)
#2
Running the same code in Unity 2017.1.0b7 outputsthe following text to the Console window:
#1
#1: while (0.01791501 < 1)
The 2nd while-loop iteration never gets executed.
Reproduce 2017.1.0b7
- Open user project in 2017.1.0b7
- Open Scenes/Booting/Booting.unity
- Press PLAY
Notice the game displays a black screen and outputs the following text to the Console window:
#1
#1: while (0.01791501 < 1)
Reproduce 5.5.2p4
- Open user project in 5.5.2p4
- Open Scenes/Booting/Booting.unity
- Press PLAY
Notice the game displays an animated loading screen. I’ve attached the 5.5.2p4 project (unity_5_5_2p4_project.zip) to the bug-report as well, in case you can’t open the submitted 2017 project in 5.5 to verify.
Expected
The coroutine should continue to run the while-loop after the first yield.