Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
5
Question by Miziziziz · Jan 17, 2016 at 09:22 PM · uiscene

How can I get a list of all scenes in the build?

Hello, Scene Manager only has GetAllScenes, there is no GetAllScenesInBuildSettings. GetAllScenes doesn't work besides, it just returns one scene, even though I have way more. it might be because I'm using this script in the editor as part of some UI generation.

Anyways, here's a script a wrote for this, but, like I said, it says there's only one scene. Any idea how to work around this?

     Scene[] getAllScenesInBuild()
     {
         Scene[] allScenes = SceneManager.GetAllScenes();
         Debug.Log("total number of scenes: " + allScenes.Length); //this prints '1' when I call this function
         int numOfScenesInBuild = 0;
         for (int s = 0; s < allScenes.Length; s++) //get total number of scenes in build
         {
             if (allScenes[s].buildIndex != -1)
             {
                 numOfScenesInBuild++;
             }
         }
         Debug.Log("numOfScenesInBuild: " + numOfScenesInBuild);
 
         Scene[] scenesInBuild = new Scene[numOfScenesInBuild];
         int indexMod = 0;
         for (int s = 0; s < allScenes.Length; s++) //get total number of scenes in build
         {
             if (allScenes[s].buildIndex != -1)
             {
                 scenesInBuild[s - indexMod] = allScenes[s];
             }
             else
             {
                 indexMod++;
             }
         }
 
         return scenesInBuild;
     }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image maccabbe · Jan 18, 2016 at 12:20 AM 1
Share

EditorBuildSettings.scenes seems to work, although it's undocumented for Unity 5.

avatar image Miziziziz maccabbe · Jan 18, 2016 at 02:50 AM 0
Share

hmm, I've never heard about that, I'll give it a look

avatar image javierfed · Mar 30, 2016 at 11:53 AM 0
Share

Sorry, that wont work, as EditorBuildSettings is apart of the UnityEditor dll, which is non-distrbutable for good security reasons... I think... but yea, @maccabbe. Would be nice, I think the only way truely to do this is to loop through each scene, load each scene, grab its name in a list, then unload them... seems long and boring, but you can start with an animation or something, just render it to a canvas or something that is placed really close to the camera, then LoadAsync and wait for each to finish... I will try this and maybe write something myself...

avatar image Laurence_B · May 23, 2017 at 08:25 AM 0
Share

Do you need to get it by script or are you just curious how many scenes you have?

If you need it by script @yasirkula script should work.

5 Replies

· Add your reply
  • Sort: 
avatar image
18

Answer by yasirkula · May 23, 2017 at 08:21 AM

The question is sorta old but maybe this will help someone... With Unity 5.5, they've added SceneUtility:

 int sceneCount = UnityEngine.SceneManagement.SceneManager.sceneCountInBuildSettings;     
 string[] scenes = new string[sceneCount];
 for( int i = 0; i < sceneCount; i++ )
 {
     scenes[i] = System.IO.Path.GetFileNameWithoutExtension( UnityEngine.SceneManagement.SceneUtility.GetScenePathByBuildIndex( i ) );
 }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image insominx · Nov 07, 2017 at 06:53 PM 2
Share

I certainly did. Here's using that to populate a UI Dropdown.

 public class DropDownScenePopulator : $$anonymous$$onoBehaviour {
     void Start () {
         var optionDataList = new List<Dropdown.OptionData>();
 
         for(int i = 0; i < Scene$$anonymous$$anager.sceneCountInBuildSettings; ++i) {
             string name = System.IO.Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(i));
             optionDataList.Add(new Dropdown.OptionData(name));
         }
 
         GetComponent<Dropdown>().ClearOptions();
         GetComponent<Dropdown>().AddOptions(optionDataList);
     }

avatar image
8

Answer by jj_unity328 · Aug 10, 2018 at 07:43 AM

There is a simpler solution that also let you check if the scene is enabled in the BuildSettings.

 List<string> scenes = new List<string>();
 foreach(EditorBuildingSettingsScene scene in EditorBuildSettings.scenes)
 {
     if(scene.enabled)
         scenes.add(scene.path);
 }

Versus UnityEngine.SceneManagement.SceneUtility.GetScenePathByBuildIndex(i) which lists all, even disabled scenes and you have no way to check their status.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shieldgenerator7 · May 30, 2019 at 11:40 PM 0
Share

The class name EditorBuildSettingsScene is misspelled in your post. Here is the correct spelling: EditorBuildSettingsScene.

avatar image usernameHed · Jul 09, 2019 at 08:08 AM 0
Share

EditorBuildSettingsScene* and not EditorBuildingSettingsScene scenes.Add* and not scenes.add*

avatar image Liderangel · Jul 31, 2019 at 08:05 PM 0
Share

Wouldn't recommend since you can't use EditorBuildSettings in build.

avatar image usernameHed Liderangel · Aug 01, 2019 at 07:19 AM 0
Share

Add a scene in the build at runtime is non-sense, because if you are at runtime, that mean the scene is already in the build. And to get another scene... you would need to rebuild, right ?

avatar image Benjiiiee usernameHed · May 28, 2020 at 09:30 PM 3
Share

It's not just for adding scenes though, in my case I made a scene menu to quickly change scenes. So it's usefull to get a list of scenes in the build settings, even in a build.

avatar image
2

Answer by HoloLensPadawan · Sep 04, 2019 at 09:18 PM

Using System.IO

         // Get build scenes
         var sceneNumber = SceneManager.sceneCountInBuildSettings;
         string[] arrayOfNames;
         arrayOfNames = new string[sceneNumber];

         for (int i = 0; i < sceneNumber; i++)
         {
             arrayOfNames[i] = Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(i));
         }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by TZ- · Mar 17, 2018 at 10:43 PM

@yasirkula

You sir are amazing, after 2 days googling a problem I was having finally my googlefu found you, I had been trying every single suggestion I could find all to no avail.

your code works perfectly in my editor script I'm trying to make ( I say trying as I am just a learner at c# and Unity) thank you so much I was very nearly going to give up and mark it as something I would have to come back to later once I had learned more. :D

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by sebtoun · Oct 15, 2021 at 08:38 PM

Here is a more concise way:

 string[] scenes = EditorBuildSettings.scenes
             .Where( scene => scene.enabled )
             .Select( scene => scene.path )
             .ToArray();



Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

53 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Different scenes or single scene for a space rpg ? 1 Answer

Canvas breaks on scene change 0 Answers

Text.text doesnt work after scene change 2 Answers

Previous UI text sticks around even after reloading scene using SceneManager.LoadScene(scene.name); 0 Answers

My button won't load a scene 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges