Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Loading Scenes from Asset Bundle

Discussion in 'Editor & General Support' started by Piflik, Sep 3, 2015.

  1. Piflik


    Sep 11, 2011
    I am currently looking into AssetBundles for a current project, where I need to be able to load new Scenes from external sources, without rebuilding the application. AssetBundles seemed ideal for this, but I encountered a little roadblock when I try to load Scenes form a bundle.

    Loading the bundle itself is not a problem, and also getting the scene paths ist quite straight forward, but these paths are unusable.

    This is what I currently do in order to load a scene from a bundle, which looks extremely stupid to me...

    Code (CSharp):
    1. private void LoadBundle() {
    3.         AssetBundle bundle = AssetBundle.CreateFromFile("AssetBundles/testbundle");
    5.         Application.LoadLevel(ToScene(bundle.GetAllScenePaths()[0]));
    6.     }
    8.     private string ToScene(string path) {
    10.         string[] parts = path.Split('/');
    12.         string scene = parts[parts.Length - 1];
    14.         return scene.Remove(scene.Length - 6);
    15.     }

    Is there a better way to get a usable string to load a Scene than this? Or is this an oversight on Unity's part?