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

Feature Request Manually preloading assetbundles

Discussion in 'Addressables' started by Clay_More, Jul 27, 2023.

  1. Clay_More

    Clay_More

    Joined:
    Dec 17, 2015
    Posts:
    11
    Hi,

    In our project we have been using old API for AssetBundles, managing them directly from code. Then we decided to move to addressables with hope to solve some common known issues with old workflow.
    What have been always very important to us, was the ability to decide in runtime whether we want to load single asset from bundle, or preload all assets this bundle contains. It seems like something very fundamental - during loading screens usually you want to preload whole bundle to pull necessary data ASAP and shorten loading times, but in runtime, when game is running and needs to maintain smooth framerate, you can't preload whole bundles which can take significant amount of time. In old api we had an access to low-level bundles api and could decide when we want to call `AssetBundle.LoadAllAssetsAsync()`.
    To our big suprise it seems like it is not possible in addressabless api anymore, you can specify
    AssetLoadMode for given bundle only before building actual bundles ! It is ridiculous as you are not able always to predict when you would be able to preload bundles or not. It is critical issue as we are struggling to optimize loading times and avoid any performance spikes in runtime at the same time.

    Is this issue already addressed ? Solutions which seems to be available right now is either completely modding addressables package code or abandon addressabless at all and use old-way API. Do you have any workarounds or tips for that ?
     
  2. Alan-Liu

    Alan-Liu

    Joined:
    Jan 23, 2014
    Posts:
    345
    A possible workaround:
    Code (CSharp):
    1. IEnumerator Start()
    2. {
    3.     var locationHandle = Addressables.LoadResourceLocationsAsync("Sphere");
    4.     yield return locationHandle;
    5.  
    6.     var location = locationHandle.Result[0];
    7.     Addressables.Release(locationHandle);
    8.  
    9.     foreach (var dep in location.Dependencies)
    10.     {
    11.         if (dep.Data is AssetBundleRequestOptions options)
    12.         {
    13.             options.AssetLoadMode = AssetLoadMode.AllPackedAssetsAndDependencies;
    14.         }
    15.     }
    16.  
    17.     var handle = Addressables.LoadAssetAsync<GameObject>(location);
    18.     yield return handle;
    19.  
    20.     Object.Instantiate(handle.Result);
    21.  
    22.     // ...
    23. }
    24.  
     
    Clay_More likes this.
  3. Jribs

    Jribs

    Joined:
    Jun 10, 2014
    Posts:
    154
    Are you saying the functionality to pre download bundles isnt what you are looking for?

    If you have a set of bundles labeled/named/whatever "Level 5", you can definitely pre download all of that stuff before hand whenever you want.

    Addressables.DownloadDependenciesAsync(address) would be a good place to start.
     
    Clay_More likes this.
  4. Clay_More

    Clay_More

    Joined:
    Dec 17, 2015
    Posts:
    11
    Would it work for local bundles as well ? I assumed it is designed for caching bundles from remote destination.. it's not clear from documentation, but I will check this out, thanks for the tip.