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 phillipphoenix · Sep 30, 2019 at 07:57 PM · sceneeditor-scriptingbuild settingseditor scriptingbuildsettings

Problems adding scene to build settings via code

I'm working on an editor tool, where I am creating a new scene from code using EditorSceneManager.NewScene, adding an object to it and then saving it.

After that I want to add it to build settings, which is where something goes wrong. No error pops up in the editor, but build settings looks like this after adding: Build settings error

My code for creating the scene is as follows:

 // Create new scene, add scene manager prefab, save and then close again.
 var initScene = 
     EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);
 initScene.name = "scene_name_here";
 var activeScene = EditorSceneManager.GetActiveScene();
 EditorSceneManager.SetActiveScene(initScene);
 var smToolObj = new GameObject("scene_name_here");
 var smTool = smToolObj.AddComponent<SceneManagementTool>();
 smTool.SetInput(true);
 EditorSceneManager.SaveScene(initScene, _initScenePath);
 EditorSceneManager.SetActiveScene(activeScene);
 EditorSceneManager.CloseScene(initScene, true);

My code for adding the scene to build settings looks as follows:

 if (EditorBuildSettings.scenes.Length == 0)
         {
             var newBuildSettingScenes = new List<EditorBuildSettingsScene>
             {
                 new EditorBuildSettingsScene(scenePath, true),
             };
             EditorBuildSettings.scenes = newBuildSettingScenes.ToArray();
         }
         else if (EditorBuildSettings.scenes[0].path == scenePath)
         {
             EditorBuildSettings.scenes[0].enabled = true;
         }
         else
         {
             // If it exists already, but is not first, remove it and add it again in front.
             // If it doesn't exist, add it in front.
             var newBuildSettingScenes = new List<EditorBuildSettingsScene>(EditorBuildSettings.scenes.Where(s => s.path != scenePath));
             newBuildSettingScenes.Prepend(new EditorBuildSettingsScene(scenePath, true));
             EditorBuildSettings.scenes = newBuildSettingScenes.ToArray();
         }

The code above should also add the scene as the first one in build settings and make sure that it is enabled.

I also find it weird that my new scene has the guid: 00000000000000000000000000000000. That should be something like: a58e401d4a7717443a2815ac2bc83212, right?

Can anyone tell me, why this doesn't work? I'm working in Unity 2019.1.4f1

Thanks in advance!

buildsettingserror.png (14.3 kB)
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by phillipphoenix · Oct 01, 2019 at 11:02 AM

I found out what the problem was.

When adding scenes to build settings the path must start with "Assets", for instance "Assets/scenes/name_of_scene.unity" instead of "scenes/name_of_scene.unity"

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

144 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 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 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

Getting the current BuildOptions 1 Answer

Detecting when a user starts and finishes moving an object with the Move tool in Editor 2 Answers

Create scene and add to build by script 2 Answers

Ensure Child Components Present on GameObject in Editor 1 Answer

How can I delete the Main Camera using a script? 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