LoadSceneAsync works incorrectly

Hello, I have created a coroutine for
asynchronous scene loading with moving DontDestroyOnLoad object, but there is a problem when I try to load the scene that was
loaded, it doesn’t load the correct scene, but LoadScene does.

private System.Collections.IEnumerator Load(int sceneBuildIndex)
{
    GetComponent<AudioSource>().Play();

    var leaves = transform.GetChild(0).GetComponent<RectTransform>();

    if (!disableAnim)
        while (leaves.anchoredPosition.y > -180)
        {
            leaves.anchoredPosition += Vector2.down * animSpeed * 100 * Time.deltaTime;
            yield return null;
        }

    var sceneLoad = SceneManager.LoadSceneAsync(sceneBuildIndex, LoadSceneMode.Single);
    while (!sceneLoad.isDone)
        yield return null;

    if (!disableAnim)
        while (leaves.anchoredPosition.y < 1260)
        {
            leaves.anchoredPosition += Vector2.up * animSpeed * 100 * Time.deltaTime;
            yield return null;
        }
}

NVM, i fixed it, but you will not see it here

And why, pray tell, would you not post the solution for future readers?

The problem was in my inattention, and it is not in this part of code

In other words LoadSceneAsync works correctly and this thread should be closed. Otherwise it will just attract more vague responses in the future.

1 Like