Search Unity

Store asset bundles locally

Discussion in 'Asset Bundles' started by Radrien, Apr 10, 2020.

  1. Radrien

    Radrien

    Joined:
    Aug 5, 2019
    Posts:
    2
    Hi !

    Context :
    We are building an app that has to download multiple asset bundles and store them on the user's phone. We need to be able to download an asb, store it locally and access it at a later time without downloading it again.
    As recommended we are using UnityWebRequest to manage the download.

    The issue :
    The asb download works and we can access its content. But it's not saved on the user's phone and we can't manage to find a way to do so. We tried multiple things regarding the AssetBundleManifest and the Hash (but don't quite understand how to use / access / generate them). The bundle is loaded and usable, but then nowhere to be found when we close the app.

    Here is the code where we download the bundle :

    Code (CSharp):
    1. private System.Collections.IEnumerator GetRemoteAssetBundle(IExperience experience, System.Action<WebCallbackResponse> callback)
    2.         {
    3.             string url = _asbLoadURL;
    4.  
    5.             UnityWebRequest webRequest = UnityWebRequestAssetBundle.GetAssetBundle(url);
    6.             webRequest.SetRequestHeader("FACEBOOK-AUTH", "Bearer " + _debugFacebookToken);
    7.  
    8.             yield return webRequest.SendWebRequest();
    9.  
    10.             UnityEngine.AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(webRequest);
    11.             UnityCallbackResponse response = new UnityCallbackResponse(webRequest.responseCode, null, webRequest.isNetworkError, null, bundle);
    12.          
    13.             webRequest.Dispose();
    14.             callback.Invoke(response);
    15.  
    16.             yield return null;
    17.         }
    Thanks :)