Search Unity

UnityWebRequestAssetBundle and caching. Do I need to keep the manifest file?

Discussion in 'Editor & General Support' started by swifter14, Feb 16, 2020.

  1. swifter14

    swifter14

    Joined:
    Mar 2, 2017
    Posts:
    165
    I use the following code to download my asset bundle from a server.
    1. If I run this code for a second time after a restart for my app, will it redownload the bundle or not because it's in the cache? and how will I know if it's redownloading / not downloading
    2. I read about hash and version number- how would you change this code to verify the hash and version number
    3. Do I need to keep the manifest file? When building asset bundles I get 2 files, one is the assets and another is the manifset. I upload only the assets (big file) to my server and ignore the manifest, which works fine, but in that case does it mean I can't use caching? The reason I only upload one file is because UnityWebRequestAssetBundle downloads one file.


    Build asset bundle-
    static void BuildABs()
    {
    BuildPipeline.BuildAssetBundles("Assets/abs", BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.iOS);
    }

    Load Asset Bundle
    using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(url))
    {
    yield return uwr.SendWebRequest();

    if (uwr.isNetworkError || uwr.isHttpError)
    {
    Debug.Log(uwr.error);
    }
    else
    {
    // Get downloaded asset bundle
    myLoadedAssetBundle = DownloadHandlerAssetBundle.GetContent(uwr);
    }
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,731
    This will not use caching. You have to use this same method with additional arguments to enable caching, see documentation for it.
    You pass them as additional arguments. The bundle will only be loaded from cache if cached bundle has the same name and version or hash or both depending on arguments used, otherwise it will be downloaded (and cached).
    No, you don't need it for caching purposes. The purpose of it is to provide you metadata about your bundles. If you don't make use of it, you don't need it at all.
     
  3. tgrotte

    tgrotte

    Joined:
    Apr 17, 2019
    Posts:
    25
    Could you tell us what the recommend way of using/sourcing the version number is? I have been using the asset bundle's file hash value, but in more recent times I noticed Unity does not recommend that approach. You can see that here in the first post. It says that the asset bundle's hash is just an estimation and not a true hash. And my experience is consistent with this- I will sometimes see the same hash value being used for bundles with slightly different binary content. The quoted text vaguely mentions something about using a CRC value. Could this be the CRC value from the asset bundle's .manifest file? I'm very curious to hear what the best practice is on this point and what most people in industry do. Thanks.