Search Unity

Is it possible to load a scene from an asset bundle outside of play mode?

Discussion in 'Asset Bundles' started by Crayz, May 2, 2020.

  1. Crayz

    Crayz

    Joined:
    Mar 17, 2014
    Posts:
    193
    I need to load a scene from an asset bundle within the editor, here is my attempt:
    Code (CSharp):
    1.             var filePath = EditorUtility.OpenFilePanel("Import FSM File", Application.dataPath, "fsm");
    2.             if(!string.IsNullOrEmpty(filePath))
    3.             {
    4.                 var mapData = FSMMapData.ReadFromFile(filePath);
    5.                 var bundle = AssetBundle.LoadFromMemory(mapData.AssetBundle);
    6.                 var scenePath = bundle.GetAllScenePaths()[0];
    7.                 EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Additive);
    8.             }
    error: ArgumentException: Scene file not found: 'Assets/Maps/Test Map/Test Map.unity'.

    I can't find a way to load a scene from memory, it seems the editor scene utility only works with files. Is there a way?
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    I don't think this is possible. EditorSceneManager.OpenScene will only work with paths of scenes in your project, not from asset bundles.
     
  3. senfield

    senfield

    Joined:
    Apr 1, 2019
    Posts:
    31
    I tried to do this too at one point and met with nothing but failure.