Load scene from asset bundle

I have asset bundle with single asset → “Assets/scene.unity”. I try to instantiate my scene on Android with Unity 5:

string[] scenePath = bundle.GetAllScenePaths();
Debug.Log(scenePath[0]); // -> "Assets/scene.unity"
Object myScene = bundle.LoadAsset(scenePath[0]);
if(myScene != null)
    Instantiate(myScene);

However, myScene is null. Can you please help?

Hello !

Scenes are not used like normal assets inside an Assetbundle and are not Objects that you can instantiate.

The way you have to use a scene is the following :

string[] scenePath = bundle.GetAllScenePaths();
Debug.Log(scenePath[0]); // -> "Assets/scene.unity"
SceneManager.LoadSceneAsync(System.IO.Path.GetFileNameWithoutExtension(scenePath[0]));

In fact, you don’t even have to call GetAllScenePaths() to make it works.
At the moment you use the www.assetbundle getter that give you your “bundle” variable, all scenes in it can be loaded with Application.LoadLevel() with their name.

Edit: updated with comments and new API.

Application.LoadLevel() is obsolete. Using SceneManager.LoadSceneAsync() works. use this:

string[] scenePath = bundle.GetAllScenePaths(); 
Debug.Log(scenePath[0]);
SceneManager.LoadSceneAsync(System.IO.Path.GetFileNameWithoutExtension(scenePath[0]));