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 DerDerErIst · Nov 11, 2018 at 04:18 PM · sceneloadloadingasync

Unloading a loaded Scene when load Async for a Loading Bar

Hey Community,

got a problem about Loading and Unloading Scenes

My approach ist to make a Loading Scene. In this Loading Scene you can load various Levels.

But in my Case i cannot Unload the Level while it isLoading

     public void LoadLevel(string sceneIndex)
     {
         //Stop Old Coroutine
         StopCoroutine("LoadAsynchonously");
         //Reset everything
         ResetLoad();
 
         //Check in what Level we are and if we are loading a Level then we want to Unload the Level
         if (load == "LevelThree" && load != "0" || load == "LevelTwo" && load != "0")
         {
             Debug.Log("Unload " + load);
             if (load == "LevelTwo")
             {
                 SceneManager.UnloadSceneAsync("Scenes/LevelTwo.unity");
             }
             else
             {
                 SceneManager.UnloadSceneAsync("Scenes/LevelThree.unity");
             }
         }
         else if (load == "LevelThree" && load != "0" || load == "LevelOne" && load != "0")
         {
             Debug.Log("Unload " + load);
             if (load == "LevelOne")
             {
                 SceneManager.UnloadSceneAsync("Scenes/LevelOne.unity");
             }
             else
             {
                 SceneManager.UnloadSceneAsync("Scenes/LevelThree.unity");
             }
         }
         else if (load == "LevelTwo" && load != "0" || load == "LevelOne" && load != "0")
         {
             Debug.Log("Unload " + load);
             if (load == "LevelOne")
             {
                 SceneManager.UnloadSceneAsync("Scenes/LevelOne.unity");
             }
             else
             {
                 SceneManager.UnloadSceneAsync("Scenes/LevelTwo.unity");
             }
         }
         //Set the new Level
         load = sceneIndex;
         //Start Coroutine to load the new Level
         StartCoroutine("LoadAsynchonously", load);
     }
 
     void ResetLoad()
     {
         //Reset everyting in Scene
         loadingScreen.SetActive(false);
         operation = null;
         activateLevelButton.gameObject.SetActive(false);
         slider.value = 0;
         progressText.text = "0%";
     }
 
     IEnumerator LoadAsynchonously(string sceneIndex)
     {
         //Set the Loading Bar and UI Active
         loadingScreen.SetActive(true);
         //Get the Operation
         operation = SceneManager.LoadSceneAsync(sceneIndex);
         //Make the Operation not complete by his Own so User can Decide when to start
         operation.allowSceneActivation = false;
 
         //While Loading it chance the UI
         while (!operation.isDone)
         {
             float progress = Mathf.Clamp01(operation.progress / .9f);
             Debug.Log(progress);
             slider.value = progress;
             progressText.text = progress * 100f + "%";
             if (progress > .9f)
             {
                 activateLevelButton.gameObject.SetActive(true);
 
             }
             //return Null ist finish
             yield return null;
         }
     }
 
     public void ActivateLevel()
     {
         //User can activate the new Level
         operation.allowSceneActivation = true;
     }

So my main problem is when the "User" Decides to load Level One and then he Change his mind and say i want load Level Two, he will Press the Button for Level Two and the System load the Second Level but never finish it and show the Button to Start the Level.

Also the first loaded Scene is still active in the hierarchy.

Here are Pictures:

alt text alt text

My first workaround was to make a Back Button and also disable the Panel with the Loading Buttons for Levels.

This prevent the User from loading another Scene Async.

So he need to decide if he want to Play the Level or want go back. In Case he press the Back Button then the whole LoadingScene gets reloaded and he is again able to Choose a Level.

But i want to archive this without reloading the LevelLoading Scene. Someone got an Idea? Thanks for Help and Hints.

levelloading2.png (253.5 kB)
levelloading.png (209.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 hectorux · Nov 12, 2018 at 12:09 AM

You could check if other scene is active when you select to load other scene, there exist SceneManager.GetActiveScene("Name"/int Index); , with this you can now unload the existing scene if it exist and dont match with the current scene to load

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

113 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

Related Questions

SceneManager.LoadSceneAsync freeze loading scene in editor. 0 Answers

Save & Load Game question 3 Answers

LoadLevel takes more time : Unity 0 Answers

heavy scene loading 1 Answer

Asyncchronous image loading 2 Answers


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