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
6
Question by HazeTI · Apr 10, 2012 at 03:51 PM · mobileloadlevelloadlevelasync

Is it possible to use LoadLevelAsync and then wait?

Hello,

So what I want to do is to load a level in the background. However I don't want the actual switch to happen until I specify. Is this possible? Currently LoadLevelAsync switches as soon as the level has been loaded.

This is for Android/iOS so we're not using streaming.

Thanks.

If you need more info just give me a shout.

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

3 Replies

· Add your reply
  • Sort: 
avatar image
20
Best Answer

Answer by TwisterK · Sep 05, 2013 at 04:53 AM

You can control the activation scene with the latest Unity, all you have to do is

 AsyncOperation op = Application.LoadLevelAsync ( "ExampleScene" );
 op.allowSceneActivation = false;

When you need to activate the scene, use this

 op.allowSceneActivation = true;

http://docs.unity3d.com/Documentation/ScriptReference/AsyncOperation-allowSceneActivation.html

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 sebas77 · Apr 10, 2012 at 04:03 PM

no you cannot do it, but since you are obviously using the pro version, what you can do is to create an assetbundle of your scene. In this way you can load the assetbundle asynchronously, then wait, then use Application.LoadLevel (which will be instantaneous because the data is all loaded).

Comment
Add comment · Show 3 · 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 HazeTI · Apr 10, 2012 at 04:05 PM 0
Share

Yes, this is what I feared. Thanks.

avatar image Gizmoi · Jun 05, 2014 at 08:48 AM 1
Share

This answer is completely incorrect.

avatar image zombience · Jan 07, 2015 at 05:07 PM 0
Share

@gizmoi can you explain why using assetbundles in this way is incorrect? i'm looking for good info on this topic.

avatar image
-1

Answer by BornInABottle · Mar 05, 2018 at 01:50 PM

Here's a working example for a Loading Screen - the loading bar updates as the scehe is loading, then devices that load in 2.5s+ will open the new scene instantly while faster devices will wait for the timer to count down before opening the scene.

 IEnumerator LoadAsynchronously(string levelName) {
 
         float timer = 0f;
         float minLoadTime = 2.5f;
 
         AsyncOperation operation = SceneManager.LoadSceneAsync(levelName);
         operation.allowSceneActivation = false;
 
         while (!operation.isDone) {
             float progress = Mathf.Clamp01(operation.progress / 0.9f);
             loadingBar.value = progress;
             timer += Time.deltaTime;
 
             if (timer > minLoadTime)
             {
                 operation.allowSceneActivation = true;
             }
 
             yield return null;
         }
 
         yield return null;
 
     }
Comment
Add comment · Show 3 · 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 HazeTI · Mar 09, 2018 at 08:38 AM 1
Share

This is quite an old question now and functionality for this has been added since with allowSceneActivation.

But I did want to comment that there is a potential problem with the code you have posted. If the operation is done before $$anonymous$$LoadTime (either if the load is very quick or you set the $$anonymous$$LoadTime too high) then allowSceneActivation will never be set to true and the scene will never switch.

If you're setting allowSceneActivation to false, then it is probably for a reason and it's much better to have allowSceneActivation set to true under some condition rather than a timer.

avatar image BornInABottle HazeTI · Mar 09, 2018 at 09:32 AM 0
Share

Thanks for the feedback. Hadn't realised the functionality was new - was just searching for a solution and couldn't find one online so posted the solution used in my game here :) Regarding operation.isDone, this is stopped at 0.9 until allowSceneActivation = true, so will never complete before $$anonymous$$LoadTime. Docs. Cheers!

avatar image HazeTI BornInABottle · Mar 09, 2018 at 10:34 AM 0
Share

Oh, I didn't know that about isDone. Good to know. Thanks!

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

LoadLevel + LoadLeveAsync = freeze? 1 Answer

Application.LoadLevelAsync() causes Unity crash? 2 Answers

LoadLevelAsynq and LoadLevelAdditiveAsynq 1 Answer

BuildPipeline.BuildPlayer - Download scenes without adding them to build menu 1 Answer

SceneManager.LoadSceneAsync causes lag spikes, how to make background loading less CPU heavy 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