x


Web Player and LoadLevelAsync

I am trying to get a web player to use LoadLevelAsync. Here are some of the problems.

  1. If I set the web player to streaming, LoadLevelAsync seems to assume that the level is ready, and jump to it straight. The streaming is then interrupted. (I am not using the streaming levels functions because the user is allowed to select a level from a menu).

  2. If the web player is not streaming, it will load all the levels and its assets, thus there is no need for LoadLevelAsync.

What is the right way to use LoadLevelAsync?

Edited: Here's the code I am using. Maybe I am doing something wrong?

public var loader : AsyncOperation;

public function Start()
{
 DontDestroyOnLoad(this);
}

public function LoadLevel( sceneName:String)
{
 loader = Application.LoadLevelAsync(sceneName);    
 yield loader;  
}

public function OnGUI()
{
 if (loader != null && loader.isDone == false)
 {
    // TODO: Change to show the progress bar
    GUI.Label(new Rect(0,20, 200, 20), "Loading..." + loader.progress);
 }
} 

To invoke it

function OnGUI()
{
         if (GUI.Button(new Rect(0,0,20, 100), "Load Level")
         {
              GameObject.Find("Loader").SendMessage("LoadLevel", "level1");
         }
}

What happens is as follow:

1) On a streaming webplayer, I get the standard Unity3D blue screen (ie, when the scene is empty). The web player just loads the new level without loading any assets or creating objects for the new level.

2) On a non-streaming webplayer, all levels were already loaded, so it makes no difference.

more ▼

asked Jun 08, 2010 at 12:23 PM

Extrakun gravatar image

Extrakun
1.5k 135 106 125

Were you able to resolve this? I think you need to check if the Asynch level has been loaded before Yielding it.

Nov 03, 2010 at 09:51 PM diabloroxx

Were you able to resolve this by checking isDone before yielding it?

Jul 23, 2013 at 11:10 PM ikelaiah
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

You need to use Application.GetStreamProgressForLevel() to check if the level has already been downloaded. LoadLevelAsync will not download the level for you, it will just load the level objects while you are still playing, so you get rid of that short loading hickup.

If you need to download levels non-linearly, that is possible by using AssetBundles, but more complicated. Check out this example: http://unity3d.com/support/resources/example-projects/assetbundles

more ▼

answered Jun 08, 2010 at 03:57 PM

jonas echterhoff gravatar image

jonas echterhoff ♦♦
10.3k 8 30 113

This answer should be marked as the correct answer. You must check if the level is fully streamed before loading it.

Jul 24, 2013 at 12:09 AM ikelaiah
(comments are locked)
10|3000 characters needed characters left

Have you read the doc? http://unity3d.com/support/documentation/ScriptReference/Application.LoadLevelAsync.html

LoadLevelAsync allows you to load new levels while still playing the current one, show a progress bar or create a completely streaming world.

So if you have a menu level, you can load the level in the back while showing a loading bar and then switch to it, when it's ready :)

This is useful because when creating web players, you need to catch peoples attention fast. so a small starter level(plus dll's), play some music flashing color and so forth. then as soon as you'r in the menu, you start downloading lvl 1 so it's ready for the user.

In your scenario where the user can pick and choose, you really win download time for the menu level, but sadly you gotta download the level when the user pushes the button. Still useful because you can show a nice loading screen.

If you wanna read more about this kinda stuff, this is a okay read: http://unity3d.com/support/documentation/Manual/Web%20Player%20Streaming.html

Hope I helped :)

more ▼

answered Jun 08, 2010 at 12:41 PM

Usul gravatar image

Usul
567 7 8 19

Thanks; maybe I am doing something wrong with my code? I have attached my code in my edited question.

Jun 08, 2010 at 01:18 PM Extrakun
(comments are locked)
10|3000 characters needed characters left

In addition to the above answers, be aware that the objects in your new level will have their Awake and Start functions called in the same thread as your loader level, so if all the work is happening in one of those functions, you're not going to see any incremental progress.

more ▼

answered Jun 30, 2011 at 01:24 AM

Waz gravatar image

Waz
7.2k 66 62 104

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x8527
x379

asked: Jun 08, 2010 at 12:23 PM

Seen: 4213 times

Last Updated: Jul 24, 2013 at 12:09 AM