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 TheFrankman123 · Apr 17, 2012 at 02:32 PM · loadasyncasynchronous

LoadLevel Async

I am toying with Load Level Async but it isn't quite what i expect. I will give you an example of how I want to apply it and for what purpose.

For example I have a start screen with Play Game, Help etc. What i would like to do is start loading the first level in the background so that when they click play game it's already loaded.

The problem at the moment is with my limited knowledge of async as soon as it loads the level the game starts playing, regardless of whether they have clicked play. I could put a boolean in to check and see if they have clicked play before loading the level but that obviously doesn't fix the problem because then it will still take the same amount of time to load as it would normally.

For further application when you reach the end of the level i have transmissions from an NPC that explain what the next level is all about and if i can't i might as well start loading the next level while they are reading. How can i achieve this.

At the moment i am using the following:

 function Start () {
     
     var async : AsyncOperation = Application.LoadLevelAsync ("level1");
     yield async;
     Debug.Log ("Loading complete");
 }

Can I achieve what i want using loadLevelAsync or do i need to use something else?

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

2 Replies

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

Answer by HazeTI · Apr 17, 2012 at 02:48 PM

I asked the same question recently: http://answers.unity3d.com/questions/238015/is-it-possible-to-use-loadlevelasync-and-the-wait.html

Basically, you can't use loadLevelAsync.

You can try using loadlLevelAsyncAdditive and have your next level start completely disabled and then use some sort of levelManager to enable gameObjects in the new level as and when you pleased. You would probably also have to use it to kick off destruction of the objects in the old level.

You could also try using AssetBundles as suggested in the answer to the question I posted.

Comment
Add comment · Show 5 · 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 TheFrankman123 · Apr 17, 2012 at 03:18 PM 0
Share

That's ridiculous... can't believe that.

$$anonymous$$oving on from my disbelief. Could you briefly describe AssetBundles just to give me somewhere to start from in my own research?

Cheers.

avatar image HazeTI · Apr 17, 2012 at 03:22 PM 1
Share

I know...

I'm afraid I can't help you with AssetBundles, I've not used them myself. Try forums/wiki/answers/google.

avatar image TheFrankman123 · Apr 17, 2012 at 04:07 PM 0
Share

I have had a thought. I am just going to do a seperate scene that has nothing on it but a gui texture saying loading. So you click play level, it takes you to the loading level scene which asyncs the next level. That way it will be very quick to load the level load scene and then the player will be aware that the game hasn't frozen it's just loading. All i really need to figure out is a level manager script so that the level loading scene knows what level you have come from and then which one to use.

So the script would have a don't destroy on it and when you click next level it adds to an int and then the script will know what level to load next.... Sounds good in theory.

avatar image HazeTI · Apr 17, 2012 at 04:16 PM 1
Share

Yup, we've pretty much done just that. Still, it's annoying that the level loading can't be started before hand and then Unity be told when to make the actual switch.

avatar image TheFrankman123 · Apr 17, 2012 at 05:45 PM 1
Share

It seems SO simplistic! Why the hell not!?

I have just whacked that out and it's working brilliantly, only problem is that it murders the Flash Export... extremely frustrating waste of time! But there you go.

Hopefully they will sort it out eventually.

Thank you for your help. Have some $$anonymous$$arma.

avatar image
1

Answer by kramcomposer · Feb 20, 2013 at 04:48 PM

Don't know if its new to Unity 4.0 but... NOTE *** If you press the STOP button in the editor, AFTER you already called loadLevel() Unity will freeze until you load the level completely

this works:

 public class loadLevelAsync{
     public static AsyncOperation async;
     
     public void loadLevel(){
         async = Application.LoadLevelAsync("MyBigLevel");
         async.allowSceneActivation = false;
     }
     
     public void startLevel(){
         async.allowSceneActivation = true;
         async = null; //because I made it a static member
     }
 }
Comment
Add comment · Show 2 · 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 RodolfoLasparri1 · Feb 24, 2013 at 10:51 PM 0
Share

so I tried that exactly and when I execute "async.allowSceneActivation = true;" anywhere Unity freezes completely and I have to restart it.

What Unity version are you using and how are you calling the method?

thanks for a lead on this strea$$anonymous$$g issue :)

avatar image kramcomposer · Feb 25, 2013 at 04:44 AM 0
Share

I'm using Unity Pro 4.0.1 PC version. Be sure you Level is added to the build. and first I call loadLevel() method, I do some things that take awhile like 3-4 seconds plus, then I call startLevel() ..

BIG NOTE * Unity Editor will Freeze / Crash if you press the STOP button once you've started the AsyncLoadLevel, meaning.. once you have started the loading of the level, you need to let it finish, and load that level, or Unity will freeze if you try to Stop playback

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

7 People are following this question.

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

Related Questions

Asyncchronous image loading 2 Answers

How to load scene when async.progress is 0.9? 0 Answers

Load menu via SceneManager 0 Answers

LoadLevelAsync - Stops Randomly? 1 Answer

Odd behaviour when preloading multiple scenes 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