Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question A few questions about asset bundles caching

Discussion in 'Asset Bundles' started by RafaelGomes00, Aug 3, 2022.

  1. RafaelGomes00

    RafaelGomes00

    Joined:
    Aug 13, 2020
    Posts:
    73
    Hello, I have a few questions about Asset bundle caching, that I couldn't find anywhere, and this is my last resource, since most part of the documentation is obsolete, or not clear enough:

    Edit: Playing around with this system i managed to get 2 of these questions answered.

    Answered:
    1. When I create an asset bundle, i get the following files: "AssetBundles / AssetBundles.manifest / {BundleName android and iOS versions} / {BundleName android and iOS versions}.manifest" and their respectives meta files.
      1. For me to use Unity internal caching system, i should download both archives separately, or save at least manifest file locally, so I can compare hash files?
        Answer: No, for you to use unity cache system, you have to get the .manifest of the folder you created the asset bundles in, for example, my folder was named "AssetBundles", then the manifest that i needed to use was AssetBundles.manifest

      2. How this caching system even works? I made some tests and it appeared that it was downloading from the internet anyway.
        Answer: Using the hash available on "AssetBundles.manifest" (got from previous question) you can use
        Code (CSharp):
        1. UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url, hash, 0);
        And use Unity's Cache / Caching classes to manage cache.
    Not answered:
    1. Am I really unable to create my own cache system? If I am able to do it, how could I save the downloaded asset bundles into a file? It returns me an error like "Asset bundles can't be used as raw data" or something like that, i don't remember exactly.

    2. On my project, I have something like a "Preview" of a content that is downloaded from asset bundle, and the whole content that is another asset bundle, so, for it, i would like to have different caching from both of them, one that the player would have on his device for a small amount of time, and another permanent if the player actually purchase the content.
      1. Am I able to clear only specific objects inside the cache? Or specific caches?
      2. Caching.ClearCache(int timeInSeconds) -> Removes asset bundles that are not used in a specific amount of time. Will remove asset bundles individually? That is, if i used asset bundle A but didn't used asset bundle B for a specific amount of time, both of them would be Removed, or only B would be removed?
        1. Would this function works even if the application is not running? for example, The player download the bundle, and it is configured to auto-remove in 2 hours, after that time will the asset bundle be removed?
    I will be really grateful for anyone who could answer any of these questions, I'm really confused about this, and it's driving me insane.
     
    Last edited: Aug 9, 2022
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    You can definitely build your own caching layer. Asset Bundles are just files - you can download them and save them on your device.