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

Issue using ClearDependencyCacheAsync

Discussion in 'Addressables' started by FlorianBernard, Jun 27, 2021.

  1. FlorianBernard

    FlorianBernard

    Joined:
    Jun 9, 2015
    Posts:
    165
    So I'm working on an Android app where user can pre-download a level, then clear it from cache anytime he wants (to save disk space), then download it again. The problem is when trying to download the level again after having cleared it and without restarting the app: DownloadDependenciesAsync completes instantly and LoadSceneAsync is then unable to load the scene.

    Flow goes as followed:
    1. Addressables.GetDownloadSizeAsync(sceneKey) => handle.Result return the expected bytes value (> 0)
    2. Addressables.DownloadDependenciesAsync(sceneKey) => takes some time to download, completes just fine, device storage decreases as expected
    3. Addressables.LoadSceneAsync(sceneKey) => Works just fine.

    Later on...

    1. Addressables.ClearDependencyCacheAsync(sceneKey) => Completes just fine and device storage increases as expected
    2. Addressables.GetDownloadSizeAsync(sceneKey) => handle.Result returns the expected bytes value on Android (though note that on Windows/Editor using Use Existing Builds it does not, it returns 0)
    3. Addressables.DownloadDependenciesAsync(sceneKey) => completes instantly, which is not expected, and device storage does NOT decrease.
    4. Addressables.LoadSceneAsync(sceneKey) => Unable to open archive file: /storage/emulated/0/Android/data/com.company.app/files/UnityCache/Shared/8ecd1ec47a1fed29f84ee74cfb5d5a5a/8fe28bc38aa00eb9de936545507572b0/__data
      Failed to load 'archive:/CAB-7317b2578dc9ae87229d00e0668ac411/CAB-7317b2578dc9ae87229d00e0668ac411.sharedAssets'. File may be corrupted or was serialized with a newer version of Unity.

    You can find the logcat stack trace here here.

    Any help, feedback or workaround would be much appreciated!

    Edit: Reproduced on Addressables 1.16.19 and 1.18.9

     
    Last edited: Jun 27, 2021
  2. FlorianBernard

    FlorianBernard

    Joined:
    Jun 9, 2015
    Posts:
    165
  3. FlorianBernard

    FlorianBernard

    Joined:
    Jun 9, 2015
    Posts:
    165
  4. TreyK-47

    TreyK-47

    Unity Technologies

    Joined:
    Oct 22, 2019
    Posts:
    1,795
    I'll kick this over to the team for some guidance.
     
    FlorianBernard likes this.
  5. davidla_unity

    davidla_unity

    Unity Technologies

    Joined:
    Nov 17, 2016
    Posts:
    736
    Yeah, this definitely doesn't seem right. If you haven't already would you mind submitting a bug for this issue?
     
  6. FlorianBernard

    FlorianBernard

    Joined:
    Jun 9, 2015
    Posts:
    165
    @davidla_unity Thanks for your feedback.

    Though I figured what I was doing wrong while working on a new bug report project for you. I noticed something I didn't realize before: ClearDependencyCacheAsync(key, false) was producing an "AssetBundle 'xxx' with hash 'yyy' is still in use" warning and handle.Status was returning Failed.

    After double checking my handles were properly being released, I later understood the issue was elsewhere: to get a precise download progress, I use
    DownloadDependenciesAsync(key).GetDownloadStatus().Percent in Update, but I wasn't releasing that handle. Doing so fixed the issue. ClearDependencyCacheAsync now succeed as expected.

    Though, I still find it odd the device storage was increasing and subsequent LoadSceneAsync crashing despite ClearDependencyCacheAsync having failed. This might be something you'll want to investigate (fyi, scene size was large, about 600MB).

    Thanks again!
     
  7. abhishek_unity872

    abhishek_unity872

    Joined:
    Jul 4, 2022
    Posts:
    1