- Home /
Getting Scenes in Project From Editor
Is there a way to get the scenes in the project while in an Editor Script. I would imagine there would be a way to get them from AssetDatabase or something, but I cannot find anything on it.
In the end, I could just get the names of everything in a particular folder, and assume that the folder will always be only scenes, but that would be pretty poor coding.
Any thoughts?
Answer by Wolfram · Jun 25, 2012 at 12:12 AM
The docs mention something about an EditorBuildSettings.scenes array, using an EditorBuildSettingsScene class, which is not further explained. Maybe the various answers here will help you: http://answers.unity3d.com/questions/10482/accessing-buildsettings-from-buildsettingsasset.html
If you're lucky, you'll get directly an object reference to your scene asset from that. Otherwise, if you get the path, use AssetDatabase.LoadMainAssetAtPath. If you get a GUID, use AssetDatabase.GUIDToAssetPath to get a path, and so on.
Bad URL for the first link, the working one is: http://docs.unity3d.com/412/Documentation/ScriptReference/EditorBuildSettings-scenes.html
Answer by karolwieczorek9 · Jun 15, 2018 at 12:02 PM
My solution:
var scenesGUIDs = AssetDatabase.FindAssets("t:Scene");
var scenesPaths = scenesGUIDs.Select(AssetDatabase.GUIDToAssetPath);
Small improvement: add "Where(s => s.StartsWith("Assets/"))" to avoid read-only scenes in packages like Packages/com.autodesk.fbx/Tests/Runtime/BuildTestsAssets/BuildTestScene.unity
Your answer
Follow this Question
Related Questions
Custom Editor: show asset folders in ObjectField 2 Answers
Change angle of camera in prefab preview 4 Answers
Access or remove background color of AssetPreview 2 Answers
How to Load/Unload assets in Editor? 0 Answers
how to properly add custom scene(s) to a custom package in Samples~ folder? 0 Answers