- Home /
Return to a scene rather than loading again
Hi,
I'm currently using Application.LoadLevel to navigate though scenes, however, returning to a scene reloads the level rather than just returning to it, this takes a huge toll on the memory and causes the android app to be slow and eventually crash.
Is there a way to not constantly load one scene on top of the other if its already been opened?
The purpose of scenes is to segment your game into pieces so that you don't have to have the entire thing in memory at once, right? You need to reload it because the application gets rid of it to make memory space for the new scene. I'm not sure how you can prevent it from doing this, but it's pretty much defeating the point of having them in separate scenes.
Then why is my app crashing when I go back to the main scene which loads fine when opening the app?? Unity does not drop all memory when changing scenes. As far as I've found out from searching, Unity is reloading ON TOP of what is already loaded. Otherwise there would be no crashing after a couple of scene changes, right? I am trying to find out how to free up memory with some sort of destroy object or memory dump. Either that or not reload into a devices RA$$anonymous$$.
The loading of a scene probably involves a GC.Collect(); command. Loading a scene whether it has been loaded before or not is a brand new one. Everything from the previous is gone and lost except if you use static or DontDestroyOnLoad. As for your issue, you need to provide some info as we can only assume without seeing your code. I would suspect the crashing to happen from the scene you are leaving not the one you are going. That is if you are not extensively using static and your first scene rely on one of them and it gets sets to 0 on first load and then gets assigned a new value later that is not appropriate anymore. Again I assume, I do not know.
Answer by Silverfell · Aug 29, 2013 at 04:44 PM
When loading a new scene, the current scene is unloaded. This can be as memory-intensive as loading. If GC gets involved, even more so.
There are some methods to help with this, such as Application.LoadLevelAdditive or its Async versions. This may be suitable to load your menu again, but probably won't work if you are running low on memory already.
Have you considered passing through a relatively empty loader scene? If switching between big levels is proving too heavy, you could pass through an empty scene, and then load a more intensive one - sounds like a proper loading manager is outside the scope of your project.