Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Other LoadSceneAsync works incorrectly

Discussion in 'Scripting' started by DZZc0rd, May 9, 2023.

Thread Status:
Not open for further replies.
  1. DZZc0rd

    DZZc0rd

    Joined:
    Sep 4, 2021
    Posts:
    58
    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.

    Code (CSharp):
    1. private System.Collections.IEnumerator Load(int sceneBuildIndex)
    2. {
    3.     GetComponent<AudioSource>().Play();
    4.  
    5.     var leaves = transform.GetChild(0).GetComponent<RectTransform>();
    6.  
    7.     if (!disableAnim)
    8.         while (leaves.anchoredPosition.y > -180)
    9.         {
    10.             leaves.anchoredPosition += Vector2.down * animSpeed * 100 * Time.deltaTime;
    11.             yield return null;
    12.         }
    13.  
    14.     var sceneLoad = SceneManager.LoadSceneAsync(sceneBuildIndex, LoadSceneMode.Single);
    15.     while (!sceneLoad.isDone)
    16.         yield return null;
    17.  
    18.     if (!disableAnim)
    19.         while (leaves.anchoredPosition.y < 1260)
    20.         {
    21.             leaves.anchoredPosition += Vector2.up * animSpeed * 100 * Time.deltaTime;
    22.             yield return null;
    23.         }
    24. }
     
  2. DZZc0rd

    DZZc0rd

    Joined:
    Sep 4, 2021
    Posts:
    58
    NVM, i fixed it, but you will not see it here
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,604
    And why, pray tell, would you not post the solution for future readers?
     
  4. DZZc0rd

    DZZc0rd

    Joined:
    Sep 4, 2021
    Posts:
    58
    The problem was in my inattention, and it is not in this part of code
     
  5. Bunny83

    Bunny83

    Joined:
    Oct 18, 2010
    Posts:
    3,429
    In other words LoadSceneAsync works correctly and this thread should be closed. Otherwise it will just attract more vague responses in the future.
     
    Kurt-Dekker likes this.
Thread Status:
Not open for further replies.