Muhammet Demir
Muhammet Demir

Reputation: 2045

can't be loaded because another AssetBundle with the same files is already loaded. error while loading different bundles

I've tried load asset bundles from URLs. When I load only single asset bundle, it works well. But if I try to load multiple asset bundles, Unity gives this error: The AssetBundle 'https://example.com/uc?export=download&id=1234567' can't be loaded because another AssetBundle with the same files is already loaded.

example code as follows

using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using TMPro;

public class sahnecagir : MonoBehaviour
{
    public TextMeshProUGUI Log;

    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(LoadBundleFromUrl("https://example.com/uc?export=download&id=123456", 2, 0, (uint)Crc.Gifts));
    }

    IEnumerator LoadBundleFromUrl(string url, int tip, uint version, uint crc)
    {
        using (UnityWebRequest uwr = UnityWebRequestAssetBundle.GetAssetBundle(url, version, crc))
        {
            uwr.SendWebRequest();

            while (!uwr.isDone)
            {
                if(tip == 1) Log.text = "Rooms loading " + (uwr.downloadProgress * 100).ToString("0")  + "%";
                else if(tip == 2) Log.text = "Gifts loading " + (uwr.downloadProgress * 100).ToString("0")  + "%";
               
                yield return null;
            }

            if (uwr.isNetworkError || uwr.isHttpError)
            {
                Debug.Log(uwr.error);
            }
            else
            {
                if (tip == 1)
                {
                    MainConfig.Instance.RoomBgBundle = DownloadHandlerAssetBundle.GetContent(uwr);
                }
                else if (tip == 2)
                {
                    MainConfig.Instance.GiftBundle = DownloadHandlerAssetBundle.GetContent(uwr);
                }
            }

           

            if (uwr.isDone && tip == 1)
            {
                Log.text = "Rooms loading 100%";
                StartCoroutine(LoadBundleFromUrl("https://example.com/uc?export=download&id=1234567", 2, 0, 0));
            }
            else
            {
                Log.text = "Gifts loading 100%";
            }
            yield return null;
        }
    }
}

Upvotes: 4

Views: 3243

Answers (2)

yasirkula
yasirkula

Reputation: 711

If multiple AssetBundles were created with the same AssetBundleBuild.assetBundleName parameter, this issue can occur. Giving unique assetBundleNames per AssetBundle can resolve this issue (even if you rename the generated AssetBundle file afterwards).

Upvotes: 0

bluewave41
bluewave41

Reputation: 145

In my case I've been trying to modify a bundle with different files but Unity refuses to load the two different files even if they have different names, a different structure, different files inside, nothing.

Opening the bundle in Notepad++ brings up what I assume to be a "container name" of CAB-a317cdbf067bab183d6dd12d870c1407 as an example. This is what Unity seems to be checking for to determine whether a bundle is "identical."

A simple find and replace to a different name and boom. The bundles load now.

Upvotes: 1

Related Questions