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 /
  • Help Room /
avatar image
0
Question by unity_sq26Sg98wIfncw · Mar 27, 2020 at 07:25 PM · scene-loadingscene-switchingload scenescene loadloadlevelasync

Order of SceneManager.LoadSceneAsync and UnloadSceneAsync.

I wrote some codes using SceneManager.LoadSceneAsync()

 IEnumerator LoadTest()
 {
 //load persistent scene(some managers are placed here)
 yield return SceneManager.LoadSceneAsync("persistentScene", LoadSceneMode.Single);

 //load first scene
 yield return SceneManager.LoadSceneAsync("firstScene", LoadSceneMode.Additive);
 
 //preload second scene
 var secondScene= SceneManager.LoadSceneAsync("secondScene", LoadSceneMode.Additive);
 
 //dont activate immediately
 secondScene.allowSceneActivation = false;
 
 //instead of fadeout
 yield return new WaitForSeconds(1.0f);
 
 //Unload first scene
 SceneManager.UnloadSceneAsync("firstScene");
 
 //activate second scene
 secondScene.allowSceneActivation = true;
 }

It works like
construct "persistentScene"
↓
construct "firstScene"
↓
construct "secondScene"
↓
destruct "firstScene"

How can i destruct "firstScene" before construct "secondScene"?

Comment
Add comment · Show 3
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 Kastenfrosch2 · Jun 21, 2020 at 09:12 AM 0
Share

Did you solve or find a workaround for your problem? I'm currently facing the same issue and don't see any way to achieve my goal. The Unloading always waits for the loaded scene to be activated :(.

avatar image unity_sq26Sg98wIfncw Kastenfrosch2 · Jun 21, 2020 at 09:24 AM 0
Share

Yes.

 //Get current scene instance 
 var currentScene = Scene$$anonymous$$anager.GetSceneByName(currentSceneName);
 
 //preload 
 var loadAsync = Scene$$anonymous$$anager.LoadSceneAsync(_nextScene, LoadScene$$anonymous$$ode.Additive); 
 loadAsync.allowSceneActivation = false;

 //wait for complete loading and fadeout
 while(loadAsync.progress < 0.9f || !Fade.IsFadeoutCompleted)
     yield return null;
 
 //Destroy GameObjects in CurrentScene 
 foreach (GameObject go in currentScene.GetRootGameObjects()) Destroy(go);

 //or like this
 //GameObject[] gameObjects = currentScene.GetRootGameObjects();
 //int maxDestroyPerFrame = 128;
 //for(int i = 0, int cnt = 0; i<gameObjects.length; ++i,++cnt)
 //{
 //    Destroy(gameObjects[i]);
 //    if(cnt > maxDestroyPerFrame) 
 //    cnt  = 0; yield return null;
 //}

 loadAsync.allowSceneActivation = true;
 yield return loadAsync;
 yield return Scene$$anonymous$$anager.UnloadSceneAsync(currentScene);






avatar image Kastenfrosch2 unity_sq26Sg98wIfncw · Jun 21, 2020 at 01:27 PM 0
Share

Hey, thanks for your answer. Its seems a bit hacky, because i don't get a sceneUnloaded-callback this way and I need special handling whenever someone asks "IsSceneLoaded", but I guess it's better than nothing :).

0 Replies

· Add your reply
  • Sort: 

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

204 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Load all scenes in splash screen 0 Answers

Printing total time to open/loading a scene 0 Answers

Multiple active scenes updating but not rendering? 0 Answers

switching scenes take a long time 0 Answers

[Unity Beginner] Game design question on scene loading and scene transitioning 0 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