Search Unity

Bug potential bug: can't do 2 loadasync consecutively on the timeline

Discussion in 'Timeline' started by laurentlavigne, Mar 17, 2021.

  1. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
  2. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
  3. DavidGeoffroy

    DavidGeoffroy

    Unity Technologies

    Joined:
    Sep 9, 2014
    Posts:
    542
    Nice use case.
    Thanks for the repro.
     
    Last edited: Mar 17, 2021
  4. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,363
    extra repro to isolate vanilla c# from timeline behaviour

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.SceneManagement;
    5.  
    6. public class _TestSceneLoading : MonoBehaviour
    7. {
    8.     public AsyncDataPipe_SO sceneSO;
    9.     public SceneReference scene;
    10.     public GameObject activateOnLoading, activateOnActivating;
    11.     public float delayBeforeLoad = 0, extraDelayBetweenLoadAndActivate = 0;
    12.  
    13.     public void Load()
    14.     {
    15.         StartCoroutine(LoadThenActivateCO());
    16.     }
    17.  
    18.     IEnumerator LoadThenActivateCO()
    19.     {
    20.         yield return StartCoroutine(LoadCO());
    21.         yield return StartCoroutine(ActivateCO());
    22.     }
    23.  
    24.     IEnumerator LoadCO()
    25.     {
    26.         yield return new WaitForSeconds(delayBeforeLoad);
    27.         activateOnLoading.SetActive(true);
    28.         activateOnActivating.SetActive(false);
    29.         sceneSO.async = SceneManager.LoadSceneAsync(scene, LoadSceneMode.Additive);
    30.         sceneSO.async.allowSceneActivation = false;
    31.     }
    32.  
    33.     IEnumerator ActivateCO()
    34.     {
    35.         yield return new WaitForSeconds(extraDelayBetweenLoadAndActivate);
    36.         while (sceneSO.async.progress < 0.9f)
    37.             yield return null;
    38.         activateOnActivating.SetActive(true);
    39.         activateOnLoading.SetActive(false);
    40.         yield return null;
    41.         sceneSO.async.allowSceneActivation = true;
    42.     }
    43. }
    View attachment 816755
    so this button is calling both loadings, each one staggered in time like so
    load 1
    load 2
    activate 2
    activate 1

    this works flawlessly in the editor and on switch
    scene loaded size 300MB