The AssetBundle can't be loaded because another AssetBundle with the same files is already loaded.

Hi,
I’m trying the assetbundle and it’s awesome ! I can build a very light game and only load the assets I need.
But if you don’t use cache, it quickly become useless !
I started just by loading the assets and drop them when I closed the game.
The loading code without cache code :

request = UnityWebRequest.GetAssetBundle(url, 0); // Work with that method : always download
UnityWebRequestAsyncOperation op = request.SendWebRequest(); // Set the request
while (!op.isDone) ; // Wait for download	
bundle = DownloadHandlerAssetBundle.GetContent(request); // Get the bundle
return bundle.LoadAsset(asset); // return it

This is working perfectly, all my assets are correctly loaded, I can even load the same asset from the same bundle multiple times, with a simple dictionary check I can avoid multiple downloads.
But now I want to make serious business ! I thought that caching was already done but I saw that it wasn’t when I tried with my android in plane mode.

So I refactored a bit my code :

public Object LoadSync(string bundle_name, string asset)
{
    AssetBundle bundle = null;
    if (!bundles.TryGetValue(bundle_name, out bundle)) // Test if I already downloaded the bundle
    {
        // Build my url, nothing special
        string url = asset_server_name + "/" + bundles_path + "/" + platform + "/" + bundle_name;

		UnityWebRequest request;
		if (allow_cache_loading)
            // search in cache then download : doesn't work with that method
			request = UnityWebRequest.GetAssetBundle(url, 1, 0); 
		else
            // always download : work with that method
			request = UnityWebRequest.GetAssetBundle(url, 0); 

		UnityWebRequestAsyncOperation op = request.SendWebRequest(); // Set the request
        while (!op.isDone) ; // Wait download
		
        bundle = DownloadHandlerAssetBundle.GetContent(request); // Get the bundle
        bundles.Add(bundle_name, bundle); // Add the bundle to the list
    }
	
	// Return the asset
	if (bundle != null)
        return bundle.LoadAsset(asset);
	else
        return null;
}

What is strange is that my first bundle load perfectly, as long as I load something from this first bundle, thanks to my condiction, it works. But as soon as I want to load from another bundle I get the the error :
Error while getting Asset Bundle: The AssetBundle ‘bundle’ can’t be loaded because another AssetBundle with the same files is already loaded.

What I tried :

  • A lot of my bundles are just a single file named default.png, so I tried to change filenames, I still get the error.
  • I looked at the request variable, not a single time it had any error boolean to true.
  • I looked at the request response code, for the first asset loading, it’s 200 if I cleared my cache before, 0 if I didn’t which is perfect, but for the next bundles loading, the response code is 0, even if I cleared the cache, the rest of the error booleans are normals, and the bundle property is null (yay fetched null from cache). So I’m wondering why the UnityWebRequest is looking in the cache if the value is null !
  • My assets where organised as a tree to ease my workflow, all my characters assets where placed in the bundle characters/name/2d, so I though that if I had 2 characters, I would have 2 bundles named characters/char1/2d and characters/cha2/2d, which would be completely independent. It seems to be the case with the download only version, but for the caching version, it doesn’t. I believe that there is only one bundle considered : characters, which contain char1 and char2. That’s not great but if I name all my bundle differently without “/”, it works.

I have to precise that the folders containing my assets are not in the bundles.

So !
My final question is
Can we get rid of this message with an assetbundle hierarchy ?

Thanks (and congrulation) for reading my text :smiley:

TDLR : Can I use a hierarchy for my assetbundle with cache ?

CanYou get any solution of this because i also got this and i have no solution

//“I have resolved this problem using add below lines”

private AssetBundle myLoadedAssetBundle;
string bundleUrl=“”;
IEnumerator LoadAssetBundle ()
{
if (myLoadedAssetBundle != null) {
myLoadedAssetBundle.Unload(false); //scene is unload from here
}

while (!Caching.ready)
yield return null;

WWW www = WWW.LoadFromCacheOrDownload(bundleUrl, 1);
yield return www;

if (!string.IsNullOrEmpty(www.error))
{
Debug.Log(www.error);
yield return null;
}
myLoadedAssetBundle = www.assetBundle;
}