Search Unity

Resources.LoadAsync doesn't work on scene loading

Discussion in 'Editor & General Support' started by JuGGerNaunT, Jun 12, 2019.

  1. JuGGerNaunT

    JuGGerNaunT

    Joined:
    Oct 28, 2014
    Posts:
    9
    I'm trying to async load some objects at scene start. But Resources.LoadAsync work the same way as Resources.Load. It load assets synchronously. It happens only if I start coroutine at Awake method and in some specific cases at Start and only at scene loading.
    Why is this happening?
    Code (CSharp):
    1. private void Awake()
    2. {
    3.     StartCoroutine(LoadAsync());
    4. }
    5.  
    6. private IEnumerator LoadAsync()
    7. {
    8.     DateTime startTime = DateTime.Now;
    9.     int startFrame = Time.frameCount;
    10.  
    11.     for (int i = 0; i < AssetsCount; i++)
    12.     {
    13.         string fileName = "texture" + i;
    14.         ResourceRequest request = Resources.LoadAsync<Texture2D>(fileName);
    15.         Debug.Log("Async start " + Time.frameCount);
    16.         yield return request;
    17.         Debug.Log("Async finish " + Time.frameCount);
    18.         Texture2D texture = (Texture2D)request.asset;
    19.         Resources.UnloadAsset(texture);
    20.     }
    21.  
    22.     var frames = Time.frameCount - startFrame;
    23.     var time = DateTime.Now - startTime;
    24.     Debug.Log("Frame count " + frames);
    25.     Debug.Log("Time " + time);
    26. }
    The result is:
     
  2. JuGGerNaunT

    JuGGerNaunT

    Joined:
    Oct 28, 2014
    Posts:
    9