Issues with WWW.LoadFromCacheOrDownload

We’re having issues with caching of AssetBundles in iOS. We download the manifest, then download and load all of the AssetBundles in the manifest before the game starts. Everything is downloaded properly and the game works fine.

Next time we launch the game, however, some of the using WWW.LoadFromCacheOrDownload (http://docs.unity3d.com/ScriptReference/WWW.LoadFromCacheOrDownload.html), with the exact same version as before (same version is used for all the AssetBundles), 90% of the AssetBundles are loaded from cache, but a few are downloaded again, even though nothing changed in the bundles, their version, or the version we provide.
Has anyone ever encountered this? Any solutions?

Hi Tomer,

According to the Unity LoadFromCacheOrDownload documentation :

If the cache folder does not have any space for caching additional files, LoadFromCacheOrDownload will iteratively delete the least-recently-used AssetBundles from the Cache until sufficient space is available to store the new AssetBundle. If making space is not possible (because the hard disk is full, or all files in the cache are currently in use), LoadFromCacheOrDownload() will bypass Caching and stream the file into memory like a normal “new WWW()” call.

Then yes, it is possible that some assetbundle will be downloaded again if the cache does not have enough space to download everything.

Edit :

If you want to make sure that your assetbundle will always be available while the player is offline, the only way to go is to NOT use the LoadFromCacheOrDownload on assetbundle from the server and download them yourself.
Here is how I did it on my side :

  1. Build your assetbundle and create a json file (or xml or whatever…) which contains for each assetbundle the version number and a md5 hash of its binary.
  2. When the player launch the game, read the json file from your server and compare the version number between the player saved game and the server current value. If it is the same, check the md5 hash (just to be sure it is nor corrupted).
  3. If the version from the server is newer or the md5 hash differs, download the package from the server using new WWW() and save it as the new version. You should be able to save it in the Application.persistantDataPath but be careful on iOS with the cloud save game which may try to save all the assetbundle in the cloud (it will be a cause of failure while submitting if so).
  4. When everything is done, the player got a downloaded version of each assetbundle and a file (json, xml, encrypted binary…) which contains the current version of each assetbundle in its saved game directory. At this point, you can use the LoadFromCacheOrDownload using your local path and the current assetbundle version to use all your assetbundle like if you were online, avoiding any caching limitation.

This solution does not works for a WebPlayer build because you cant save any binary file on the disk with this build target

@pitimoi
I am trying to implement pitimoi’s approach to hadle AssetBundles, but I faced a lot of difficulties.

Can anybody share C# script implementing this approach?

Thank you in advance.