Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Raptcha911 · Feb 15 at 11:01 AM · scene-loadingstuckasynchronous

LoadSceneAsync never completes if allowSceneActivation is set to false

Hello,

I'm working on a project using Unity 2021.2.11f1 and I'm facing a weird issue where loading the scene asynchronously never completes if allowSceneActivation is set to false in the asyncOperation.

Here is my custom scene loading method

 private IEnumerator LoadScene(string sceneName, LoadSceneMode loadMode, bool enableOnLoad = false)
         {
             //If the scene name is empty or if there is scene load already in progress, just exit
             if (sceneName.IsNullOrWhitespace() || _loadSceneOperation != null && !_loadSceneOperation.isDone)
                 yield return null;
 
             //Load scene asynchronously
             _loadSceneOperation = SceneManager.LoadSceneAsync(sceneName, loadMode);
 
             //BUG: Currently setting allowSceneActivation to false causes the scene loading to get stuck and never call the OnSceneLoaded event
             _loadSceneOperation.allowSceneActivation = enableOnLoad;
 
             _loadSceneOperation.completed += SceneLoadingOperationCompleted;
 
             while (_loadSceneOperation != null && !_loadSceneOperation.isDone)
                 yield return null;
         }

And here is how I call it

 StartCoroutine(LoadScene(MainSceneName, LoadSceneMode.Additive));

The AsyncOperation never finishes and SceneManager.sceneLoaded event never gets triggered.

And in the editor the scene shows up as 'is loading' perpetually alt text

If anyone has any idea, please advice!

screenshot-2022-02-15-162948.png (1.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 rh_galaxy · Feb 15 at 11:13 AM

In your while loop, you need to allow scene activation at 90%, or it will never activate.

 //wait until the asynchronous scene fully loads
 while (!_loadSceneOperation.isDone)
 {
     //scene has loaded as much as possible, the last 10% can't be multi-threaded
     if (_loadSceneOperation.progress >= 0.9f)
     {
         //(here you can do other stuff, like custom loading or something)
         //then when done, you must call
         _loadSceneOperation.allowSceneActivation = true;
     }
     yield return null;
 }
Comment
Add comment · Show 4 · 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 Raptcha911 · Feb 15 at 11:28 AM 0
Share

Well, that's the thing. I don't want to activate the scene as soon as its loaded. I have an animation that I want to complete before making the scene visible. Which is why I call the below method after animation completion

 private void OnSplashSequenceComplete()
         {
             if (_mainSceneLoaded)
             {
                 //Set the main scene as active after the splash sequence is complete
                 SceneManager.SetActiveScene(SceneManager.GetSceneByName(MainSceneName));
             }
         }

But the problem here is that the '_mainSceneLoaded' boolean is always false because its set to true in the SceneManager.sceneLoaded callback which never gets called if the allowSceneActivation is set to false.

If I just set the allowSceneActivation to true while loading the scene, everything works fine but the scene becomes visible while the animation is still playing which is not what I want.

avatar image rh_galaxy Raptcha911 · Feb 15 at 11:46 AM 0
Share

Maybe I missed something with _mainSceneLoaded, but this might work

 bool splashComplete = false;
 
 private void OnSplashSequenceComplete()
 {
     splashComplete = true;
 }
 
 //in the while loop
 if (_loadSceneOperation.progress >= 0.9f)
 {
     if(splashComplete)
         _loadSceneOperation.allowSceneActivation = true;
 }
avatar image Raptcha911 rh_galaxy · Feb 15 at 12:09 PM 0
Share

I see. I guess I can wait for splashCompletion in scene loading method instead of checking for scene loading completion in the splash animation method. I can make this work. Thanks for the workaround suggestion.

But the doubt still remains in my mind. The SceneManager.sceneLoaded event does not get called if allowSceneActivation is set to false while loading Async. Is this by design? Does the SceneManager.sceneLoaded callback not get called until the scene has been activated?

Show more comments

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

135 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

Related Questions

SceneManager.LoadScene used within promise (or async callback) does nothing 0 Answers

Get a reference to the newly loaded scene after a LoadSceneAsync() 2 Answers

Particular scene loads fine in the Unity Editor, but unable to load in the executable? 0 Answers

Can Jobs be used to load large scenes asynchronously without freezing? 1 Answer

About unnactive scenes and performace... 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