• 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 saldavonschwartz · Jun 24, 2015 at 05:07 AM · unity 5loadlevelasync

allowSceneActivation only works once in the editor when trying to delay loading a scene.

I'm trying to delay reloading a level until after I'm done showing some animation. My code is basically:

 IEnumerator killPlayer(GameObject player) {
     AsyncOperation reload = Application.LoadLevelAsync(Application.loadedLevel);
     reload.allowSceneActivation = false;
     
     while (**<some condition>**) {          
       // Show the player dying, some animation, etc
       yield return null;
     }
     
     while (reload.progress < 0.9f) {
       yield return null;
     }
     
     reload.allowSceneActivation = true;
   }

As you can see, the key thing is the setting of allowSceneActivation to false so that even if the scene is done loading, it won't kill the current scene until eat least after my other animations are done (the first while loop). By the time the first loop is done, the next one potentially waits until we reached the infamous undocumented 90% and only then do I re-enable allowSceneActivation to finally load the scene.

When I try this in the editor, the first time around it works just fine. But after working once, it never again reloads the scene, because the second while never breaks, because the progress is stuck at 0.

Any thoughts?

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 zach-r-d · Jun 24, 2015 at 07:56 AM 0
Share

Why not remove the second while loop? What's preventing reallowing scene activation as soon as the desired condition is fulfilled?

FWIW, progress being stuck at 0 in the editor seems to be a known bug.

avatar image saldavonschwartz · Jun 24, 2015 at 08:23 AM 0
Share

interestingly, I take out the while and it works. So I guess I'll leave it out. The reason why I had the while was cause even at 90% loaded, if I allowed the scene to load I could still tell there was a bit of overhead. But whatever, at least it works. And thanks for the tip on the editor bug.

avatar image TrollAxeThrower · Feb 18, 2016 at 11:05 AM 0
Share

@saldavonschwartz Have you found a solution to this?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

24 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

Related Questions

Got a problem with Async! 0 Answers

LoadLevelAsync multiple pending scenes? 0 Answers

unity LoadSceneAsync works like LoadScene 0 Answers

Trouble With Loading Bar Script C# Unity 5 1 Answer

LoadLevelAsync never executes on a background thread? 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges