Cant load assetbundle for a second time from cache without an error

Hello, So I have this problem where I have a button that downloads and loads an asset bundle from the server
then looks for a scene in the bundle and loads the scene, after I’m done with the scene and go back to the main scene that has the button, I trigger again the button and I get the following error Error while getting Asset Bundle: The AssetBundle 'blahblahassetbundle can’t be loaded because another AssetBundle with the same files is already loaded.
I tried to add AssetBundle.UnloadAllAssetBundles(true); on the start function of the main scene but the asset bundle is still loaded and I still get the same error.
When I restart the game the Assetbundle loads normally when I press the button without downloading it again but directly from cache. which is what I want to happen when I come back to the main scene.

Button Script

    public void PlayDLCbyString(string dlcname)
    {
        DLC_Name = dlcname;
       
        StartCoroutine(DownloadScene());

    }

Downloading the bundle and loading the scene

private IEnumerator DownloadScene()
    {
        yield return GetBundle(mUri + "files/" + DLC_Name);

        if (!mBundle)
        {
            // Debug.Log("Bundle Failed to Load");
            yield break;
        }

        //   mBundle.LoadAllAssets();
        if (mBundle.isStreamedSceneAssetBundle)
        {

            string[] scenePath = mBundle.GetAllScenePaths();
            //Debug.Log(scenePath[0]);
            //scene load scene from bundle
            ScenePath = System.IO.Path.GetFileNameWithoutExtension(scenePath[0]);
            //SceneManager.LoadSceneAsync(System.IO.Path.GetFileNameWithoutExtension(scenePath[0]));

            Camera.main.GetComponent<LoadUnLoad>().Load(ScenePath);
        }




    }
 private IEnumerator GetBundle(string src)
    {
        WWW request = WWW.LoadFromCacheOrDownload(src, 0);
        yield return request;

        while (!request.isDone)
        {
            //downloading
            DownloadingCanvas.gameObject.SetActive(true);
            ProgressBar.fillAmount = request.progress;
            //  Debug.Log(request.progress);

            yield return null;


        }

        if (request.error == null)
        {
         
//where the error occurs.
             mBundle = request.assetBundle;
   
         


            //Debug.Log("Sucess");
        }
        else
        {

            //if error show error
            Camera.main.GetComponent<LoadUnLoad>().Load(SceneManager.GetActiveScene().name);

        }

    }

Did you call this anywhere?

I dont know how to call this correctly. for example, if i call this after I’m done with the scene and I’m back to the main scene. the assigned Assetbundle mBundle object is already gone since the scene with the script has been reloaded. Maybe i should try to make the variable static so it’s not lost . and then when I’m back to the main scene the script would keep the bundle and possibly unload it. ill try it today. thanks for the reply. :slight_smile:

May you want this instead: Unity - Scripting API: AssetBundle.GetAllLoadedAssetBundles

Thank you for this looks like a good option also, I made the mBundle variable static, and then when the main scene with the script gets loaded again the bundle won’t get lost and I can unload it using mBundle.Unload(true);