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 /
avatar image
1
Question by yeoldesnake 1 · Sep 27, 2011 at 01:24 PM · loadbackgroundlevelasyncloadlevelasync

Using LoadLevelAsync to load a level in the background , but initiate the level changing after something is done

I have an introductional video as the first level of my game.

As it plays , i want the menu level to be loaded in the background , but only change the level when the video is done playing. I currently have this which does not work.

 var introVid:AsyncOperation;
 var movieTexture:MovieTexture;
 var canLoad:boolean=false;
 function Start(){
 movieTexture.Play();
 LoadLevelAsynchronously();
 camera.main.audio.Play();
 Debug.Log("level was loaded");
 }
 function OnGUI () {
 GUI.DrawTexture(Rect(0,0,Screen.width,Screen.height),movieTexture,ScaleMode.StretchToFill);
 if(!movieTexture.isPlaying)
 canLoad=true;
 }
 
 function LoadLevelAsynchronously(){
 introVid=Application.LoadLevelAsync("Menulvl");
 while(!introVid.isDone&&canLoad==false)
 yield;
 
 
 }

What am i doing wrong here?

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 msknapp · Sep 27, 2011 at 09:57 PM 0
Share

can you describe the symptoms? Is it just not playing the video? Do you get any runtime exceptions or warnings?

$$anonymous$$y guess is that when the movie is downloading but has not started, the "movieTexture.isPlaying" function will return false because it is technically not playing. Even though I see you telling the movie to play, it might not start immediately. Just because a movie is not playing does not mean it has finished, it might have not started. You might need to check the "movieTexture.isReadyToPlay" function too.

$$anonymous$$ight want to add some debug statements to see what the initial value of "movieTexture.isPlaying" returns.

Also, in your while loop, I would change "&&" to "||", though I don't think that is the culprit.

If it just seems to never do anything, you might need to wrap the line "LoadLevelAsynchronously();" with "StartCoroutine()" and make the function return an Enumerator.

avatar image yeoldesnake 1 · Sep 28, 2011 at 08:13 AM 0
Share

It is playing the video , it interrupts it halfway through though when the level loading is finished , i set it to yield until canLoad gets true , which only gets true when the video is finished , but it is not working.

avatar image cregox · Oct 10, 2011 at 08:45 PM 0
Share

related: http://answers.unity3d.com/questions/170089/using-asyncoperation-for-our-own-services.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by HazeTI · Sep 19, 2012 at 02:50 PM

I know this is a really old question but as I came across this when searching for something else I thought I'd answer.

It's basically exactly what I asked here and the answer is that you can't use LoadLevelAsync to choose when to switch levels. It will load the level in the background but then switch as soon as it is ready.

You could use AssetBundles to achieve something, as pointed out in the above link.

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 HazeTI · Sep 19, 2012 at 02:56 PM 1
Share

Actually this answer is even better: http://answers.unity3d.com/questions/137261/loading-level-async-without-switching-the-level-im.html

avatar image cregox · Sep 19, 2012 at 03:01 PM 0
Share

@HazeTI rather than adding a comment, you could/should've edited your answer... The second idea indeed seems much better! Also, try bringing the content from any link into your answer, with your own words like you did for the first one. ;-)

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Loading/unloading a background-loaded level manually using LoadLevelAsync() (Possible?) 1 Answer

How to load levels with animation GUI 1 Answer

Loading Level Async without switching the level immediately 5 Answers

Load Level Additive Async Lag spike 0 Answers

app freeze and threading 2 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