Search Unity

Question Create SceneAsset list from EditorBuildSettings.scenes

Discussion in 'Editor & General Support' started by AlphaLulz, Mar 20, 2023.

  1. AlphaLulz

    AlphaLulz

    Joined:
    Sep 2, 2019
    Posts:
    51
    Is there any way for me to create a list of SceneAssets that is the same as the scenes included in
    EditorBuildSettings.scenes? I know that this article tells you how to do it the other way around, but I can't find a way to convert an EditorBuildSettingsScene to a SceneAsset. I can get the scene path from the EditorBuildSettingsScene, but for some reason, SceneAssets don't have a constructor that can take a scene path and create the SceneAsset.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,925
    Doing a bit of a search I can't see that you can create scene asset's easily via code.

    Most of seen is a combination of
    EditorSceneManager.NewScene
    +
    EditorSceneManager.SaveScene
    .
     
  3. AlphaLulz

    AlphaLulz

    Joined:
    Sep 2, 2019
    Posts:
    51
    I'm not talking about the actual scene in the project, but rather the "SceneAsset" class in Unity, which is used to reference scenes in the inspector. It doesn't have a constructor, so I don't know how to automatically assign a value to it.
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,925
    I mean it has a path to the asset. So just
    AssetDataBase.LoadAssetAtPath
    ?
     
    AlphaLulz likes this.
  5. AlphaLulz

    AlphaLulz

    Joined:
    Sep 2, 2019
    Posts:
    51
    Oh yeah, that seems to work. Thanks for the help!