0
\$\begingroup\$

I want all of my scenes to load when the loading screen is shown (but only one should be shown at a time) so I can switch between them quickly I have tried this:

if (Application.GetStreamProgressForLevel (2) == 1) {
    Application.LoadLevel (2); Application.LoadLevelAdditive (1);

and:

(Application.GetStreamProgressForLevel (2) == 1) {
Application.LoadLevelAdditive (2);
Application.LoadLevelAdditive (1);
Application.LoadLevel (1)
\$\endgroup\$
  • 1
    \$\begingroup\$ I reformatted the code to be more readable, but I don't get what it's doing or why it's a problem. \$\endgroup\$ – Anko Jan 6 '14 at 14:09
  • \$\begingroup\$ I don't think there is a way to do precisely what you're asking for, but then doing precisely what you're asking for would eat up a lot of memory so are you sure you'd want to? The typical approach to seamless loading of new levels is to use LoadLevelAsync as the player nears the next level. Incidentally, LoadLevelAdditive doesn't do what you want; LoadLevelAdditive doesn't preload levels, it adds the new level without destroying the old level. \$\endgroup\$ – jhocking Jan 6 '14 at 14:19
1
\$\begingroup\$

First of all loading all scenes into memory may not be a good idea. Depending on your scene size, you can quickly exhaust all the available memory. In addition why do you want to load additive all your scenes? Eventually use a single scene if you know that you are loading all the scenes anyway.

In any case, just a little clarification. When you load a scene into memory, all the objects in the scene will be added to the hierarchy (scene graph). At that point you cannot distinguish no more which object belong to which scene.

When I want to keep track of which GameObjects belong to which scene (usually when I use load level additive and lightmaps), I organize my scene using a root node for each scene, in such a way that all objects belonging to the scene N, have a common root node Root_N . This way if you want to unload the scene N -1 you can just call Destroy on the relative root GameObject (Root_N -1).

I guess that in a simliar way if you attach a script to the root GameObject of each scene (starting from the second ), that is responsible for disabling the relative node in Start method, you will obtain a similar result.

public class RootSceneHandler : MonoBehavior // attached to the root gameobject. Disabling the root node will provoke each children to become invisible too.
{
  void Start()
  {
    SetActive(false);
  }
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.