gowthy
gowthy

Reputation: 3

Unity assetbundle scene unload

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.

Upvotes: 0

Views: 4000

Answers (1)

Muhammad Faizan Khan
Muhammad Faizan Khan

Reputation: 10541

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

Maybe you will find this proper asset bundle guide.

Upvotes: 0

Related Questions