Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug AssetBundle Progress not displayed

Discussion in 'Asset Bundles' started by unity_z5FF_KMJqnSrEw, Apr 15, 2021.

  1. unity_z5FF_KMJqnSrEw

    unity_z5FF_KMJqnSrEw

    Joined:
    Nov 25, 2018
    Posts:
    1
    I am trying to create a loading bar for an assetBundle. Loading the bundle from file happens very fast ( <0.1s), but instantiating the asset in my scene takes quite long (~30s), so that progress I want to display in order to demonstrate something is happening and the application has not crashed.

    When trying to display the progress via AssetBundle, it goes immediately from 0 (first frame) to 1 (second frame) and stays there for the next thirty seconds.

    I am using Unity 2020.3.0f1, URP. The AssetBundle in question is a large (really large >19000000 verts) mesh and several materials with their respective textures. All of those assets are loaded from the hard drive, it's not a download.

    Am I doing something wrong or is this on Unity's end?

    I appended some of the console log (one line per frame for 30 seconds is a lot of lines, between the two shots there's nothing but the time ticking up), below's my code:


    Code (CSharp):
    1. private void OnEnable()
    2.     {
    3.         StartCoroutine(_LoadBundle(true));
    4.     }
    5.  
    6. float timeStamp = 0f;
    7.     private IEnumerator _LoadBundle(bool value)
    8.     {
    9.         // load AssetBundle from path
    10.         timeStamp = Time.time;
    11.         var request = AssetBundle.LoadFromFileAsync(path);
    12.         while (!request.isDone)
    13.         {
    14.             assetBundleLoadProgress = request.progress;
    15.             yield return null;
    16.         }
    17.         Debug.Log("loadFromFileAsync done after " + (Time.time - timeStamp));
    18.         timeStamp = Time.time;
    19.         if (request.isDone)
    20.         {
    21.             assetBundle = request.assetBundle;
    22.             if (!assetBundle)
    23.             {
    24.                 Debug.LogError("AssetBundle is invalid for " + path, this);
    25.                 yield break;
    26.             }
    27.             var loadOp = assetBundle.LoadAllAssetsAsync();
    28.             loadOp.allowSceneActivation = false;
    29.             while (!loadOp.isDone)
    30.             {
    31.                 assetLoadProgress = loadOp.progress;
    32.                 Debug.Log("LoadAllAssetsAsync inprogress " + (Time.time - timeStamp) + " : " + loadOp.progress);
    33.                 yield return null;
    34.             }
    35.             Debug.Log("LoadAllAssetsAsync done after " + (Time.time - timeStamp));
    36.             if (loadOp.asset)
    37.             {
    38.                 Debug.Log("Are we waiting here?");
    39.                 var rootAsset = (GameObject)loadOp.asset;
    40.  
    41.                 // parent correctly
    42.                 Debug.Log("Root asset from bundle: " + rootAsset.name);
    43.                 instance = Instantiate(rootAsset);
    44.                 instance.transform.SetParent(this.transform, false);
    45.  
    46.                 OnLoadingDone?.Invoke(this.gameObject);
    47.             }
    48.             assetBundle.Unload(false);
    49.             Debug.Log("We're done." + (Time.time - timeStamp));
    50.         }
    51.     }
     

    Attached Files: