- Home /
Loading scene from asset bundle fails in Unity 4
I used to load a level (scene) from a bundle after I it is downloaded in Unity 3. Same code fails to run in Unity 4 throwing an exception saying that :
Level 'name of my scene' (-1) couldn't be loaded because it has not been added to the build settings. To add a level to the build settings use the menu File->Build Settings...
Here is a code I am using:
...
stream = new WWW(url));
yield return stream;
stream.assetBundle.LoadAll();
Application.LoadLevel(levelName);
...
Even the Unity's sample project generates the same exception and doesn't work.
Please note that the scene is not available in the starter package and has to be loaded from a bundle.
Any idea?
$$anonymous$$y guess is you should rebuild the bundle. I don't think that 3.x-bundles are loadable with Unity 4.x.
I did that but it didn't work. Actually with 3.x bundle there was another error after I rebuilt it with 4 the I got the above error message.
Answer by Ab00 · Nov 20, 2012 at 04:05 AM
The problem was that in Unity 4 when you want to load a level (scene) the name is case-sensitive. In Unity 3 this was not case-sensitive.
As far as I know, every string-based method has been case-sensitive in Unity for ages.
Well, I have to downgrade and test it again in unity 3.x to be 100% sure but as far as I look at my codes from before I used call ToLower() before loading the level and it used to work.
Thanks!
I was having the same issue. As soon as I started using the case-sensitive name it worked. Note that, the issue wasn't really apparent as loading scene without asset bundle doesn't require case-sensitive scene name.
Answer by Baastax · Nov 19, 2012 at 12:14 PM
You can't use Application.LoadLevel to load assets in asset bundles.
Instead you should call Instantiate(stream.assetBundle.mainAsset);
I am not instantiating an object. What I want to do is loading a scene which is inside a bundle.
This is incorrect. stream.assetBundle.mainAsset is always null for a streamed scene assetBundle.