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
0
Question by Master-of-Games · Jul 07, 2016 at 07:24 AM · scenebuild settings

Add scenes to build through script?

The title says it all. Is there anyway i can add scenes to build settings through scripts?

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 EpiFouloux · Jul 07, 2016 at 09:14 AM 0
Share

I don't know the answer, but I would like to know why you need to do such thing

avatar image EDevJogos · Jul 07, 2016 at 03:00 PM 0
Share

i'm also curious why would you need this ?

avatar image EpiFouloux EDevJogos · Jul 08, 2016 at 10:11 AM 0
Share

Why do we get down votes for curiosity?

avatar image Master-of-Games · Jul 15, 2016 at 04:46 PM 0
Share

Hey guys, i solved the problem and thanks for replying. I was actually building a level editor for my game and was worried how can a user post their scene to the server and will it be possible to open a scene from server? The solution is ins$$anonymous$$d of posting scene , a user can post the game objects under an xml file i guess(i mean do the serialization process to save the required data). But still thank you for responding, really appreciate it

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Jessespike · Jul 07, 2016 at 05:37 PM

Not documented very well, but should be clear enough to use. It's an Editor script you'll need to include UnityEditor namespace.

 EditorBuildSettings.scenes

---------- edit ----------

EditorBuildSettings is deprecrated since 5.3, use EditorSceneManager instead. Thanks to chomps32 for correction.

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 gilley033 · Oct 31, 2017 at 04:16 PM 0
Share

I cannot find any methods in the new EditorScene$$anonymous$$anager class that allow you to modify the build setting scenes. If you could point one out, that would be great, but otherwise, I think your initial answer of using EditorBuildSettings is still the only way to do this.

avatar image
0

Answer by chomps32 · Jul 08, 2016 at 10:30 AM

@Jessespike that class is depreciated since 5.3,

Use EditorSceneManager:

http://docs.unity3d.com/ScriptReference/SceneManagement.EditorSceneManager.html

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 Jessespike · Jul 08, 2016 at 04:13 PM 0
Share

Nice correction, thank you

avatar image
0

Answer by gilley033 · Oct 31, 2017 at 04:22 PM

I could not find any method to do this using the EditorSceneManager, and I don't see anything about EditorBuildSettings being deprecated.

Here is how I do it:

 void AddSceneToBuildSettings(string pathOfSceneToAdd)
 {
         //Loop through and see if the scene already exist in the build settings
         int indexOfSceneIfExist = -1;
 
         for (int i = 0; i < EditorBuildSettings.scenes.Length; i++)
         {
             if (EditorBuildSettings.scenes[i].path == pathOfSceneToAdd)
             {
                 indexOfSceneIfExist = i;
                 break;
             }
         }
 
         EditorBuildSettingsScene[] newScenes;
 
         if (indexOfSceneIfExist == -1)
         {
             newScenes = new EditorBuildSettingsScene[EditorBuildSettings.scenes.Length + 1];
 
             //Seems inefficent to add scene to build settings after creating each scene (rather than doing it all at once
             //after they are all created, however, it's necessary to avoid memory issues.
             int i = 0;
             for (; i < EditorBuildSettings.scenes.Length; i++)
                 newScenes[i] = EditorBuildSettings.scenes[i];
 
             newScenes[i] = new EditorBuildSettingsScene(pathOfSceneToAdd, true);
         }
         else
         {
             newScenes = new EditorBuildSettingsScene[EditorBuildSettings.scenes.Length];
 
             int i = 0, j = 0;
             for (; i < EditorBuildSettings.scenes.Length; i++)
             {
                 //skip over the scene that is a duplicate
                 //this will effectively delete it from the build settings
                 if (i != indexOfSceneIfExist)
                     newScenes[j++] = EditorBuildSettings.scenes[i];
             }
             newScenes[j] = new EditorBuildSettingsScene(pathOfSceneToAdd, true);
         }
 
         EditorBuildSettings.scenes = newScenes;
 }
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

7 People are following this question.

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

Related Questions

Unity Scene File in Build Question 1 Answer

Manually Edit EditoBuildSettings.asset 0 Answers

Scene could not be loaded even though it is in build settings 0 Answers

Create scene and add to build by script 2 Answers

How do I remove a scene from a build 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