Search Unity

[SOLVED]Caching.ClearOtherCachedVersions not working

Discussion in 'Asset Bundles' started by xiaoguangxing, Dec 12, 2019.

  1. xiaoguangxing

    xiaoguangxing

    Joined:
    May 15, 2019
    Posts:
    14
    This is my c# code for clearing cache,all Caching.ClearOtherCachedVersions invoking return true, but clear nothing. Is that because of I request assetbundle with UnityWebRequestAssetBundle.GetAssetBundle(Uri uri, uint version, uint crc) not UnityWebRequestAssetBundle.GetAssetBundle(string uri, Hash128 hash, uint crc = 0)?
    Code (CSharp):
    1. public void ClearOtherCachedVersions(Action<long, long> progressCb = null) {
    2.     if (manifest == null) {
    3.         progressCb?.Invoke(0, 0);
    4.         return;
    5.     }
    6.     var assetBundles = manifest.GetAllAssetBundles();
    7.     for (var i = 0; i < assetBundles.Length; ++i) {
    8.         var clearCache = Caching.ClearOtherCachedVersions(assetBundles[i], manifest.GetAssetBundleHash(assetBundles[i]));
    9.         Debug.Log(clearCache
    10.             ? $"Caching.ClearOtherCachedVersions() successfully, assetBundle name {assetBundles[i]}"
    11.             : $"Caching.ClearOtherCachedVersions() failed, assetBundle name {assetBundles[i]}");
    12.         progressCb?.Invoke(i + 1, assetBundles.Length);
    13.     }
    14. }
     
  2. xiaoguangxing

    xiaoguangxing

    Joined:
    May 15, 2019
    Posts:
    14
    I am trying to use UnityWebRequestAssetBundle.GetAssetBundle(string uri, Hash128 hash, uint crc = 0) to get asset bundle, but when I try to get hash of asset bundle for manifest with following code, it always return "00000000000000000000000000000000“,I wonder why?

    Code (CSharp):
    1. BuildPipeline.GetHashForAssetBundle("path/to/assetbundle/output/path/Android", out var hash1);
    2. Debug.Log(hash1.ToString());
     
  3. xiaoguangxing

    xiaoguangxing

    Joined:
    May 15, 2019
    Posts:
    14
    Code (CSharp):
    1. Caching.ClearOtherCachedVersions("assetBundleName", new Hash128(0U, 0U, 0U, verInfo.crc))
    This code clear nothing too.:(
     
  4. xiaoguangxing

    xiaoguangxing

    Joined:
    May 15, 2019
    Posts:
    14
    Well, it is working now, the first parameter of Caching.ClearOtherCachedVersions should not contain any path of assetbundle, it must be only file name of assetbundle, otherwise, it will fail.
     
unityunity