0

I have created few assetbundle scenes for my project. Now I am downloading the assetbundles and able to load scenes. Here the problem is that when I run a scene and exit from that and try to reload the same scene once again, it is giving an error like

"The Assetbundle mywebsite.com/bundles/assetbundle.unity3d can't be loaded because another AssetBundle with the same files is already loaded."

Im not able to open the scene for second time. Can anyone tell the problem and help me to resolve?! Thanks in advance.

Im adding the code here:

IEnumerator sceneLoad()
{

    WWW www = WWW.LoadFromCacheOrDownload(myurl,version); 

    while (!www.isDone) 
    {

        msg.text = "Downloading...";

        float progress = Mathf.Clamp01 (www.progress / .9f);

        progressslide.value = progress;

        float val = progress * 100f;

        double value = System.Math.Round (val, 2);

        progresstext.text = value + "%";

        Debug.Log ("Progress " + progresstext.text);

        yield return null;

    }

    bundle = www.assetBundle;

    msg.text = "Opening Scene...";

    progressslide.gameObject.SetActive (false);

    progresstext.gameObject.SetActive (false);

    string[] scenepath = bundle.GetAllScenePaths ();

    Debug.Log (scenepath [0]);

    var async = SceneManager.LoadSceneAsync(System.IO.Path.GetFileNameWithoutExtension (scenepath [0])); 

    yield return null;

    bundle.Unload (false);  
}

The above code is perfectly working on unity engine in my pc but when I build apk and run on phone, the progress bar is not working but bundle is downloading and scene is opening. Later when I exit the scene, comes to my app main page and again open the same scene, it was showing the error as

"The Assetbundle mywebsite.com/bundles/assetbundle.unity3d can't be loaded because another AssetBundle with the same files is already loaded."

I am using Vuforia in the downloaded scene.

gowthy
  • 3
  • 2
  • 5

1 Answers1

0

You should unload the loadded asset bundle when you exit the scene.

Maybe you will find this proper asset bundle guide.

Muhammad Faizan Khan
  • 10,013
  • 18
  • 97
  • 186
  • Thanks for your reply. I have tried unload(false) but no luck – gowthy Oct 10 '18 at 11:53
  • provide some code and check this https://support.unity3d.com/hc/en-us/articles/115000178003-I-m-downloading-an-AssetBundle-and-I-m-getting-an-error-Cannot-load-cached-AssetBundle-A-file-of-the-same-name-is-already-loaded-from-another-AssetBundle- – Muhammad Faizan Khan Oct 10 '18 at 11:54
  • @gowthy did you read the manual provided in this answer? In the section `After loading prefab again` it says `For most projects, this behavior is undesirable. Most projects should use AssetBundle.Unload(true) and adopt a method to ensure that Objects are not duplicated. ` did you try that instead? – derHugo Oct 10 '18 at 15:44
  • @derHugo I didnt try this. Will try that and in mean time I added the code above. Pls check and let me know if there are any changes or suggestions – gowthy Oct 11 '18 at 05:11
  • I solved it by writing the scene name directly like SceneManager.LoadSceneAsync("scene name") instead of System.IO.... and yield return async in the below line. – gowthy Oct 16 '18 at 12:57