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);
}
}