Search Unity

AssetBundles and DownloadHandlerAssetBundle Version control problem

Discussion in 'Scripting' started by plyrek, May 11, 2017.

  1. plyrek

    plyrek

    Joined:
    Mar 2, 2015
    Posts:
    15
    I am trying to create an app that downloads AssetBundles based on an AR target that is scanned. I have a separate bundle for each target and one of the bundles contains dependencies. I can get the program to work correctly one time through. i.e. App locates target A and bundle A loads, I then locate target B and bundle b loads (with its dependencies) however, if I then go back to target A I get this series of errors.

    The AssetBundle 'http://localhost/AssetBundles/Android/modAR002' can't be loaded because another AssetBundle with the same files is already loaded.

    Error while getting Asset Bundle: The AssetBundle 'http://localhost/AssetBundles/Android/modAR002' can't be loaded because another AssetBundle with the same files is already loaded.

    NullReferenceException: Object reference not set to an instance of an object
    AssetBundleManagerCloud+<InstantiateObject>c__Iterator1.MoveNext () (at Assets/Mod_C_Scripts/AssetBundleManagerCloud.cs:84)

    If you look at my Manager script I am using version numbers for both the unityWebRequest and the DownloadHandlerAssetBundle. My understanding was this was supposed to stop the requests from happening if an AssetBundle is already in the cache.

    Code (CSharp):
    1.  
    2. IEnumerator InstantiateObject()
    3.     {
    4. string  uri = "http://localhost/AssetBundles/Android/" + assetBundleName;
    5. [INDENT]UnityEngine.Networking.UnityWebRequest request = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(uri, 1, 0);[/INDENT]
    6.         DownloadHandlerAssetBundle handler = new DownloadHandlerAssetBundle(uri, 1, 0);
    7. request.downloadHandler = handler;
    8.             yield return request.Send();
    9.             //To load all assets
    10.             AssetBundle bundle = handler.assetBundle;
    11.             UnityEngine.Object[] assetObjectArray = bundle.LoadAllAssets();
    12.  
    13.             foreach (UnityEngine.Object obj in assetObjectArray)
    14.             {
    15.                 GameObject i = obj as GameObject;
    16.                 theCurrentObject = Instantiate(i, this.transform);
    17.             }
    18. }
    19.  
    If anyone could help explain to me why the version control on this download script isn't stopping the attempt to download the AssetBundle again and is throwing the errors I would greatly appreciate it.

    Thank you.