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
1
Question by TruffelsAndOranges · Dec 21, 2015 at 10:42 PM · scenescene-loading

Why is it not supported to unload the firstly loaded scene?

Why is it not supported to unload the firstly loaded scene?

You basically get this error message if you try (and then the scene does not unload):

 Unloading the last scene Assets/Scenes/Game/World 1 - Garden/W1_FirstKey.unity(index: 4), is not supported. Please use SceneManager.LoadScene()/EditorSceneManager.OpenScene() to switch to another scene.

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

4 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Lariosss · Mar 28, 2020 at 05:50 PM

For anyone still looking the answer for this.

You have to set the new scene as "Active", before unloading the previous one.

 SceneManager.LoadScene("Untitled", LoadSceneMode.Single);
 SceneManager.SetActiveScene(SceneManager.GetSceneByName("Untitled"));
 SceneManager.UnloadSceneAsync("SampleScene");
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 dedemonn · Jan 04, 2021 at 10:17 PM

Encountered this problem in my unit tests, where for each test I was recreating a fresh scene. Basically solution was as Bunny83 said (which I missed and solved it 2h later :D).

 public static IEnumerator CreateScene() {
         var previousScene = SceneManager.GetSceneByName("Game");
         if (previousScene.IsValid()) {
             yield return SceneManager.UnloadSceneAsync(previousScene);
         }
 
         SceneManager.LoadScene("Scenes/Game", LoadSceneMode.Additive);
         var scene = SceneManager.GetSceneByName("Game");
         while (!scene.isLoaded) {
             yield return new WaitForSeconds(0.1f);
         }
 }
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
0

Answer by Bunny83 · Dec 21, 2015 at 11:15 PM

I still haven't Unity 5.3 but the error says something else than what you said in your title:

 Unloading the last scene XXX is not supported

That means you only have one scene loaded at that moment. Unloading that scene would mean you literally destroy everything in your scene.

Unloading a scene only makes sense when you first load another scene additively. Usually when you call SceneManager.LoadScene you load the scene in single mode. So the previous scene would be unloaded automatically when the new scene is loaded.

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
0

Answer by RocketFriday · Mar 05, 2021 at 11:24 PM

Similarly to Lariosss's answer because this did fix the error, however not at first because for anyone using the SceneManager.onsceneloaded event it turns out the event passes the loading screen scene a few times before sending the scene ACTUALLY PASSED IN lol So you gotta make sure the scene exists, before following Lariosss's answer.

Like dis:

 private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
     {
         try
         {
             if (scene == SceneManager.GetSceneAt(1))
             {
                 print("Level Loaded...");
             }
         }
         catch (System.IndexOutOfRangeException s) { return; }
         StartCoroutine("SwitchActive"); // <--- using Lariosss's answer 
     }
 
 




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

36 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

Related Questions

Classic Resident Evil-style room loading/level streaming? 4 Answers

,Enums not being passed between scripts properly 1 Answer

How do I reset part of a scene? 1 Answer

how to save the progress on scene1 when it goes to scene2, so when it goes back to scene1 its still the same saved scene 2 Answers

Changing scenes while preserving background 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