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.

Caching uncompressed Assetbundle

Discussion in 'Scripting' started by NoDumbQuestion, Apr 17, 2018.

  1. NoDumbQuestion

    NoDumbQuestion

    Joined:
    Nov 10, 2017
    Posts:
    186
    I have around 200 HD Images inside an Assetbundle compress as LZMA. The total file size around 50Mb. Loading onAwake with Assetbundle.LoadFile took around 10s on Android device.

    Code (CSharp):
    1. AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, AssetBundleName));
    Then I try compress bundle with LZ4, load image or Texture2D one by one with AssetBundle.LoadAssetAsync.
    Code (CSharp):
    1.     public static IEnumerator LoadAssetAsync(string assetName, Action<float> progressAction, Action<UnityEngine.Object> doneAction)
    2.     {
    3.         var assetRequest = assetBundle.LoadAssetAsync(assetName);
    4.         while (!assetRequest.isDone)
    5.         {
    6.             // [0, 0.9] > [0, 1]
    7.             float progress = Mathf.Clamp01(assetRequest.progress / 0.9f);
    8.             if (progressAction != null)
    9.                 progressAction(progress);
    10.             yield return null;
    11.         }
    12.  
    13.         if (doneAction != null)
    14.             doneAction(assetRequest.asset);
    15.     }
    On android, the game run smoothly and I saw all image loaded one by one. Unzip-loaded image(not in RAM) can be reloaded immediately. And it took around 100s or longer to decompress the whole 200 images. The devices become very hot too, hotter than normal decompression on awake.

    But when I restart the app, Assetbundle decompress the entire 200 images again. This is quite unexpected as I saw loaded Texture2D and Images can freely used without existing in RAM and no wait time when loading.

    I assume Unity cache runtime Assetbundle somewhere and not reuse it when restart the app.

    If anyone of you know how to access this cache folder or keep uncompress assetbundle on disk, it would be much help.