Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Different URL getting the same AssetBundle

Discussion in 'Asset Bundles' started by Draikz, Mar 29, 2023.

  1. Draikz

    Draikz

    Joined:
    Dec 20, 2016
    Posts:
    12
    Hello guys!

    We're having trouble downloading several Asset bundles at a time, using UnityWebRequestAssetBundle.GetAssetBundle, and giving url and version as parameters, the DownloadHandlerAssetBundle always return the same assetBundle instead of the one for each different URL.

    Let me show you the code for better understanding:

    I first create a dictionary with the urls for each bundle

    Code (CSharp):
    1. protected override void Awake()
    2.     {
    3.         base.Awake();
    4.  
    5.         bundles.Add("France", france);
    6.         bundles.Add("Egypt", egypt);
    7.     }
    And then I call the coroutine to download the different asset bundles for each country in this case, trying to use the caching system as explained in the documentation (Perhaps I din't understand it)

    Code (CSharp):
    1. public IEnumerator DownloadCountriesCoroutine(List<PackInfo> packs)
    2.     {
    3.         foreach (var pack in packs)
    4.         {
    5.             string country = pack.GetCountryTag();
    6.  
    7.             if (bundles.ContainsKey(country))
    8.             {
    9.                 string url = bundles[country];
    10.                 using (UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(url, 1u, 0u))
    11.                 {
    12.                     Debug.Log("ab. Downloading bundle: " + country);
    13.                     yield return www.SendWebRequest();
    14.  
    15.                     if (www.result != UnityWebRequest.Result.Success)
    16.                     {
    17.                         Debug.Log(www.error);
    18.                     }
    19.                     else
    20.                     {
    21.                         AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(www);
    22.                         Debug.Log("ab. Loaded " + assetBundle.name);
    23.  
    24.                         //do something with the bundle
    25.  
    26.                         assetBundle.Unload(false);
    27.                         yield return new WaitForEndOfFrame();
    28.                     }
    29.  
    30.                     www.Dispose();
    31.                 }
    32.             }
    33.         }
    34.  
    35.         downloadingCountries = false;
    36.     }
    As you can see there is a for loop iterating through every country to get its asset bundle URL but this is the result:

    upload_2023-3-29_14-0-13.png

    What can I be missing?
     
  2. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,653
    Log the url you are downloading. Likely you'll find it to be the same for both countries.
     
  3. Draikz

    Draikz

    Joined:
    Dec 20, 2016
    Posts:
    12
    I logged it and it was different, the URLs were correct.

    I fixed it using hash instead of version as parameter, but I still don't understand what was going on, maybe it's some kind of bug.
     
  4. Aurimas-Cernius

    Aurimas-Cernius

    Unity Technologies

    Joined:
    Jul 31, 2013
    Posts:
    3,653
  5. AndrewSkow

    AndrewSkow

    Unity Technologies

    Joined:
    Nov 17, 2020
    Posts:
    79
    Is there any chance the bundles you uploaded to your server were actually wrong?

    I don't see any problem in your code, but it is relying on the Assetbundle.name from the downloaded AssetBundle to prove that the wrong bundle was downloaded. I think some additional logging might help pinpoint more of what is going on, or expand out the code temporarily.

    We support multiple active UnityWebRequest objects at a time so I think the state is pretty well isolated, and in this case you are doing them one at a time. But if you can pinpoint a bug of course we would like to learn about it and fix it.