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.
  2. Dismiss Notice

EditorSceneManager.OpenScene path requirements

Discussion in 'Editor & General Support' started by FriendAndFoeMatt, Mar 15, 2016.

  1. FriendAndFoeMatt

    FriendAndFoeMatt

    Joined:
    Jan 27, 2015
    Posts:
    11
    Hi,

    The docs on SceneManager.LoadScene (and its suggested editor counterpart EditorSceneManager.OpenScene) are a bit sparse in terms of exactly what's taken into account when attempting to load a scene:

    http://docs.unity3d.com/ScriptReference/SceneManagement.SceneManager.LoadScene.html

    I'm getting the error "Cannot open scene with path..." when attempting to load a scene additively. Regardless of how I configure the Build Settings or the path I'm passing in to the call.

    I'm stripping the ".unity" extension as recommended in the docs; I've tried passing in fully qualified paths ("D:\..."), project-qualified paths ("Assets\...") and I've tried mimicking the format in Build Settings("Scenes\...") but can't get it to load.

    Any insight into the requirements (file in build settings, path requirements, etc) would be much appreciated - this is blocking our use of additive scenes currently.
     
  2. FriendAndFoeMatt

    FriendAndFoeMatt

    Joined:
    Jan 27, 2015
    Posts:
    11
    After more experimentation, EditorSceneManager.OpenScene (I can't speak for the SceneManager yet) requires a fully-qualified path including the .unity extension which directly contravenes the docs.

    In order to construct this from a Scene.path variable you'll need to do something like:
    Code (CSharp):
    1. EditorSceneManager.OpenScene(Application.dataPath + "/" + myScenePath.Substring(myScenePath.IndexOf("Scenes")), OpenSceneMode.Additive);
     
    radiantboy and soundscouts like this.
  3. Deleted User

    Deleted User

    Guest

  4. AdamBebko

    AdamBebko

    Joined:
    Apr 8, 2016
    Posts:
    161
    Is there an easy way to get a path to a scene from SceneAsset? SceneAsset.path is not there like one would expect
     
  5. devardeb

    devardeb

    Joined:
    Nov 7, 2020
    Posts:
    1
    If you know the name of the scene one option is running over your Asset data, but it excludes scenes that could be in the resources folder of plugins. If you know the name of the scene and this scene is set up to be build another option is to compare the name with the scene path references in EditorBuildSettingsScene.GetActiveSceneList()