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

LoadAllAssetsAsync access to the obejcts ?

Discussion in 'Scripting' started by stevensen, Mar 3, 2020.

  1. stevensen

    stevensen

    Joined:
    Oct 31, 2013
    Posts:
    7
    Hi there,
    I'm not yet very familiar with asset loading.
    I want to use LoadAllAssetsAsync. It seems to load all assets, because I can see the names of all objects. but how do I get access to the objects themselves in the Assetebundle?
     
  2. kru

    kru

    Joined:
    Jan 19, 2013
    Posts:
    452
    LoadAllAssetsAsync will return an AssetBundleRequest object, which has an "allAssets" accessor that returns an Array of the loaded assets.
    Code (csharp):
    1.  
    2. AssetBundle someBundle;
    3. var assetRequest = someBundle.LoadAllAssetsAsync();
    4. assetRequest.completed += operation =>
    5. {
    6.     // The operation passed in is an AssetBundleRequest, so this is a safe cast
    7.     var request = (AssetBundleRequest) operation;
    8.     for (var i = 0; i < request.allAssets.Length; i++)
    9.     {
    10.         var asset = request.allAssets[i];
    11.         Debug.Log($"Asset {i}: {asset}");
    12.     }
    13. };
     
  3. stevensen

    stevensen

    Joined:
    Oct 31, 2013
    Posts:
    7
    Thank you very much for your helpful answer! maybe I'll get back to you on this.