Hello unity community,
This is my first post on this forum therefore: Hello everyone!
I have recently started to learn Unity for my new job. I have accustomed myself quite well and the first fruits of my work start to flourish. Unity is a nice framework. However I got a question that I can’t seem to find a good tutorial/howto about and the forum search is currently broken for me (504 timeout or just blank page).
I dynamically load scenes from asset bundles like this:
void ButtonPressed(){
string url = "file://" + Application.dataPath + "/AssetBundles/GameScene.unity3d";
StartCoroutine(DownloadAndStartLevel(url));
}
IEnumerator DownloadAndStartLevel (string url) {
WWW www = new WWW(url);
yield return www;
if ( www.error != null ) {
Debug.LogError( www.error );
www.Dispose();
yield break;
}
www.assetBundle.LoadAll();
Application.LoadLevel("Game");
}
This code works but produces an error:
The asset bundle '.../AssetBundles/GameScene.unity3d' can't be loaded because another asset bundle with the same files are already loaded
This error is produced by the line 15 (www.assetBundle.LoadAll();). However if I delete that line the LoadLevel function after it will not work anymore. If I just skip all AssetBundle loading and skip right to LoadLevel() I get the message that the scene doesn’t exist in the current build. So therefore I guess I have correctly configured the Login and Game scenes because trying to load a scene without loading its asset bundle will not work.
Even if this code still works I don’t like to get exceptions in my editor. What are the best practices for loading a scene (including the scenes assets) from an asset bundle?