Why is there no Application.UnloadLevelAdditive or UnloadLevelSubtractive? How do I drop a level that is no longer needed?
For example, if I were to go through a bulkhead of a ship and wanted to unload the level for where I was, how would I do that? Would have to unload those objects manually? It sounds to me that the new level is basically loaded as a set of objects which are quite literally added to the current scene when I use ‘LoadLevelAdditive’.
Yes, I know that I can destroy objects I don’t need. I am just curious if there is any internal indexing after using LoadLevelAdditive which tracks which objects were loaded by which scene and is useful in any way. It seems unlikely to be the case. No big deal though if it has to be done manually.
Would putting scene objects inside a master scene gameobject and simply destroying that when required, work?
I was thinking (assuming that would be a viable solution) that you could then have a special gameobject that contains important scripts you want to keep, and another gameobject with all a scenes objects in it which you can just kill in one go when needed, after loading the new area in. Which wouldn’t touch the global scripts you want to keep.
Yes, I think it would. It was kind of what I was thinking as well. So if you had one large seamless world, you would just put everything into an object and destroy it. If you had something like Bioshock you could break the game up into rooms and corridors to block views (pretty common trick) and unload things as you didn’t need them by removing the parent.
Another thing I was thinking is that you could use OnAwake as you load new items and set the location there through a location/state manager and then destroy them based on that particular variable. The state manager would have LoadArea and UnloadArea and when it unloads it would just search objects and destroy them as needed and when it loads it would just use the LoadLevelAdditive.
You can’t, because after you added a level additively its no longer present as a level at all.
its added as instantiated assets to the scene loaded before and as such you must unload them through destroy.
there is no “want” or “don’t want” in if you want to do it that way, there is only a want or don’t want in unloading, as thats the way you unload them again.
if you design your additive scenes correctly its a trivial matter by the way:
just have a main scene node of which all others are childs of and tag it and name it equally to the scene.
then its a one liner to “unload” the scene.
This is a good idea overall. The one downside is it’s nice to have all of your separate prefabs, because they all good versioned separately of the scene and each other. If you encapsulate everything in a given scene as the children of a single scene GameObject prefab then all of your various items in the scene are now directly associated to one prefab.
That’s why loading and unloading content as scenes could in some cases be more appealing than strictly loading unloading via prefab instantiation.
Also scenes can be streamed, not sure if that’s true of prefabs… have to look into it.
I was definitely hoping to approach the scene loading unloading the same way… like loading unloading a swf into a parent swf in Flash/FLEX thinking. SWFs come with MovieClips/Prefabs, which can be instantiated after you load in a SWF but to save on initial load you separate out the SWFs… in Unity we’re frequently making apps/games for mobile, in these cases you want to make sure to load as little in as possible, where as Flash is all for desktop where resources by comparison are basically unlimited… so on these Unity mobile apps anything I want to not be loaded into memory right when the app starts but that I do want to be able to access or instantiate at some point during runtime must go into a folder called Resources. Then you can load them in at runtime when you’re ready for them and they wont go into your memory foot print until you do… I think…
I just don’t see the reason for additive load without a subtractive load… when you load into a scene normally, it unloads the existing scene and does some serious garbage collection, or so I’ve been lead to believe… but what if you want some parts of the app to be persistent through the whole experience, or through an extended sequence of level loads, like a navigation bar for example… if I want a nav bar to live on and retain it’s state as sub parts of an app are loaded unloaded it seems that Application.LoadLevelAdditve( “scenename” ); and an equivalent removal function call would be the way to go.
If anyone can provide more clarity on what their strategy is for loading/unloading particularly as it pertains to resource management on mobile devices I’d be super happy to hear it.