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

How to let player redownload addressables bundles(mobile device)

Discussion in 'Addressables' started by scozirge, Feb 16, 2022.

  1. scozirge

    scozirge

    Joined:
    Feb 24, 2015
    Posts:
    77
    I would like to let players clean the bundle and redownload the bundles. This is my code below

    //1. unload all assets
    AssetBundle.UnloadAllAssetBundles(true);

    //2.ClearCache
    if (Caching.ClearCache())
    {
    Debug.Log("Successfully cleaned the cache");
    _cb?.Invoke();
    }
    else
    {
    Debug.Log("Cache is being used");
    _cb?.Invoke();
    }

    //3.ReDownload again

    Addressables.DownloadDependenciesAsync(key);


    //4. Load asset from bundle (but this phase will return error)
    //Got Error: Unable to load dependent bundle from location .......
    Addressables.LoadAssetAsync<RuntimeAnimatorController>(_path).Completed += handle =>


    Do you know how to handle this?
    Many thanks
     
  2. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    736
    AssetBundle.UnloadAllAssetBundles(true); is very dangerous to use alongside Addressables and could very likely be the cause of your issues. Instead of unloading AssetBundles directly like that, make sure you've released all of your AsyncOperationHandles so that we can decrement the ref count and unload the bundles on the back end.

    What's probably happening is that Addressables thinks that those bundles are still loaded and attempts to return the Bundle it thinks should be there. Since you've forced the bundles to unload, it can't return the correct data.

    If your purpose of re-downloading bundles is due to needing content to update, try the content update workflow. https://docs.unity3d.com/Packages/com.unity.addressables@1.19/manual/ContentUpdateWorkflow.html You can then use the Addressables.CheckForCatalogUpdates and Addressables.UpdateCatalogs at runtme.
     
    scozirge likes this.
  3. scozirge

    scozirge

    Joined:
    Feb 24, 2015
    Posts:
    77
    Thank you! I will give it a try.