0

How to let know WWW.LoadFromCacheOrDownload function to download latest version of asset bundles , so that the above fuction do not use cached asset bundles.

Aryaman Gupta
  • 616
  • 1
  • 8
  • 20

2 Answers2

0

Second parameter of this function is actually the version of asset bundles (WWW LoadFromCacheOrDownload(string url, int version, uint crc = 0);). So if you want to download new one be sure that parameter version gets higher number as its value.

Usually you do it by having the current version number somewhere online so that the client before loading assets checks the current version and pass it as parameter.

It is that simple.

However in Unity3D 5.x I had many problems with WWW.LoadFromCacheOrDownload, as it was always downloading even if the asset should be cached. But maybe it was already fixed.

Jerry Switalski
  • 2,690
  • 1
  • 18
  • 36
0

I will provide a more up to date answer since the WWW method is no longer the recommended way. See the UnityWebRequestAssetBundle class: https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequestAssetBundle.GetAssetBundle.html. Unity's caching system will handle using the version number- you only need to worry about setting it. It will re-download the asset bundle whenever you provide a new version number, or if the bundle name isn't present in the cache (a new bundle). If the version number you provide is already in cache, it will load from cache.

Note the overloads for the GetAssetBundle method, how they may take either a Hash128 or uint for the version number. I have come to find the Hash128 option misleading. It leads one to using the asset bundle's file hash value, which is conveniently provided by the asset bundle manifest. There is even an example in Unity's documentation showing this usage. But as noted in the first post here, Unity instructs that this value is an unreliable estimation which they do not recommend: https://forum.unity.com/threads/reliability-of-asset-bundle-hashes-in-assetbundlemanifest.773141/

If anyone knows what the recommended value source should be for the version number, please let me know.

Overbyte
  • 136
  • 7