Hey fellow devs,
I need some in-depth-knowledge about how Application.LoadLevel() works. As for that matter how Unity handles scene-transitions.
We’re developing a PS Vita exclusiv game - that being said we do have the hardware to test our game for the device (a DevKit and a TestKit).
Now this is the problem:
We have two scenes.
Scene_01:
And here’s the Scene_02:
As you see the second scene is bigger. We’re working with 2DToolkit for our Sprites and Ferr2D for our Terrains. And as you see, this scene has more sprites and terrains to show.
If you look at the first scene there’s a Spot labeled"SP_01" - there’s a TriggerBox where the player can press the Up-Button on the device to “march” into the woods - At this point the screen will fade out, the next scene is loaded and will fade in. So far so good.
The funny thing is that we got a bunch of errors using Application.LoadLevel() for this.
I reported the problem in the official Sony DevNet-Unity forum and the errors will be fixed in a soon-to-be-released Patch, but there’s a more crucial problem for us: the loading time.
In Editor loading the second scene takes roughly a second, which is great.
On the PS Vita DevKit/TestKit it takes up to 12 seconds. This is an absolute NoGo.
Now what’s really funny is our workaround:
Instead of using Application.LoadLevel() we do this:
for (int i = 0; i < levelObjectsToDestroy.Length; i++)
{
Destroy(levelObjectsToDestroy[i]);
}
Application.LoadLevelAdditive(levelToPreLoad);
- we’re populating a GameObject-Array with all the GOs of the current scene
- when the Player reaches the TriggerBox and hits up, we’re deleting all these GameObjects
- after that we use Application.LoadLevelAdditive() instead of .LoadLevel()
→ Boom! Loading Time goes down to roughly 1 second, like in the editor. From 12 seconds with LoadLevel() to around 1 second with LoadLevelAdditive()
(For the record, deleting the GameObjects and using .LoadLevel() shows no difference, still 12 seconds!)
I would really like read an explanation about how .LoadLevel() works internally, since we had the impression that our approach with deleting all the LevelObjects and then loading the next scene with LoadLevelAdditive(), is somewhat similar to .LoadLevel(), but it seems it isn’t.
So I’m all ears!