AssetBundle - Scenes in Unity 5

Hi,

Today I decided to give AssetBundles a try, but I ran into a problem …

I did the following:

  • According to the new Manual for AssetBundles, I tagged all my Scenes (for a test) for a single AssetBundle.
  • I built it
  • I “uploaded” it to my localhost so I could try the approach via www class.

So far, so good. Now to the problems:
I use the script below to load the AssetBundle and Instantiate a button for each Scene in the Bundle. This is working so far. The attached button script gets the name of the level in a string and if it is clicked it should just load the level. But instead of doing so it gives me the following error:

The code for loading the asset:

#pragma strict
var ButtonPrefab     : GameObject;
var ButtonCounter     : int;


var Bundle : AssetBundle;

function Start()
{
   
    var www : WWW = new WWW("http://localhost/Bundles/levels");
   
        yield www;
   
        Bundle = www.assetBundle;
        Objects = Bundle.LoadAllAssets();
       
    var Btn : GameObject;
    for(var a : String in Bundle.GetAllScenePaths())
    {
        Btn = GameObject.Instantiate(ButtonPrefab);
        Btn.name = ButtonCounter.ToString();
       
        Btn.GetComponent(Button).lvlstring = a;
        Btn.transform.SetParent(this.transform, false);
        ButtonCounter++;
    }
   
}

I tried to do some research but i found nothing that fit my problem. Maybe someone of you could help me?
I’m looking forward for your answers!

Greetings
Gushus

When using Application.LoadLevel() you shouldn’t use the whole path, only the scene name.

So instead of trying to load “Assets/Assets/_Scenes/Levels/Level10.unity”, you should simply load “Level10.unity”.

1 Like

Oops, I just realized my answer example was incorrect. The correct line would be:

Application.LoadLevel("Level10");

i.e. don’t use the “.unity” file extension.