Search Unity

How to check whether or not the requested assetbundle is loaded/cached already

Discussion in 'Asset Bundles' started by Desoxi, Nov 21, 2017.

  1. Desoxi

    Desoxi

    Joined:
    Apr 12, 2015
    Posts:
    195
    Hey there,

    i currently dont know how to prevent the error "The AssetBundle 'pathToAssetBundle/bundle can't be loaded because another AssetBundle with the same files is already loaded.".

    Im using the following routine everytime i need to access a videoclip out of this bundle:
    Code (CSharp):
    1. UnityWebRequest www = UnityWebRequest.GetAssetBundle(bundleURL, 0, 1983471844);
    2.  
    3.         // wait for load to finish
    4.         yield return www.Send();
    5.  
    6.         if (www.error != null)
    7.         {
    8.             Debug.LogError("www error: " + www.error);
    9.             www.Dispose();
    10.             www = null;
    11.             yield break;
    12.         }
    13.  
    14.         // get bundle from downloadhandler
    15.         bundle = ((DownloadHandlerAssetBundle)www.downloadHandler).assetBundle;
    "1983471844" is the CRC number out of the bundle.manifest file and i tried to use something like:
    Code (CSharp):
    1. if (!Caching.IsVersionCached("bundle", Hash128.Parse("1983471844")))
    2.         {
    3.             Debug.Log("AssetBundle not yet cached");
    4.             StartCoroutine(LoadAssetBundleCoroutine("pathtoAssetBundle/bundle"));
    5.             return;
    6.         }
    But that always returns false and doesnt seem to work.
    What exactly am i doing wrong or is there another better way of doing so?
     
  2. AlexHell

    AlexHell

    Joined:
    Oct 2, 2014
    Posts:
    167
    when you have equals filename in different ABs for example:
    example.com/bundle1 which contains file my.txt
    example.com/bundle2 which contains file my.txt
    my.txt already exist in bundle1, and you take a error on loading bundle2

    also you need 'using' around request, example:
    Code (CSharp):
    1.  
    2. using (UnityWebRequest www = UnityWebRequest.GetAssetBundle(bundleURL, 0, 1983471844))
    3. {
    4.         // wait for load to finish
    5.         yield return www.Send();
    6.         if (www.error != null)
    7.         {
    8.             Debug.LogError("www error: " + www.error);
    9.             yield break;
    10.         }
    11.         // get bundle from downloadhandler
    12.         bundle = ((DownloadHandlerAssetBundle)www.downloadHandler).assetBundle;
    13. }
    14.  
    also you don't need
    if (!Caching.IsVersionCached
    becouse of build-in caching inside UnityWebRequest.GetAssetBundle

    also the error may occur if you load same AssetBundle many times, in that case you need to load 1 time, and other times not to reload, but use exist reference to bundle; or bundle.Unload before reload
     
    Last edited: Nov 29, 2017
  3. Jeff-Kesselman

    Jeff-Kesselman

    Joined:
    Apr 5, 2010
    Posts:
    99
    That doesnt work. Same error.