Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have scene A loaded.

I load scene B with LoadLevelAdditive.

How do I unload scene B and keep scene A loaded?

share|improve this question
    
A lot of people have requested an erase method of some sort on the forums, but haven't seen anything surface about it. –  Ash Blue Jul 14 at 5:27

2 Answers 2

up vote 5 down vote accepted

You essentially need to Destroy(..) the GameObjects that came from your 2nd scene, manually.

Quick solution: for your 2nd scene, make an empty root GameObject positioned at global 0,0,0. Any other GameObject in your scene becomes a child of that. After loading the 2nd scene additively, the root will be in the hierarchy. Just Destroy(...) the root, and all GameObjects that came from the 2nd scene will be deleted too.

share|improve this answer
1  
Ok, so a scene is really just a list of objects, and once they come in, it's not really known which scene they came from. Got it. –  Almo Mar 11 at 14:34

Usually if you want the current level to unload when the new level has finished loading, you would use LoadLevelAsync instead, as it will unload the current level once the new one is finished loading. This allows you to bring up an animated loading screen or something similar.

If you're loading in multiple levels, you may have to LoadLevelAsync on the first one, and once it's complete, load all others with LoadLevelAdditiveAsync.

If you're trying to stream in and out levels, you will probably have to create a manager to destroy the objects manually once a level needs to be unloaded.

Reference: http://answers.unity3d.com/questions/18766/how-to-unload-after-calling-loadleveladditive.html

share|improve this answer
    
This does not answer my question. How do I unload a scene that has been loaded with LoadLevelAdditive? I have already read the answer you are quoting. –  Almo Mar 11 at 14:16
2  
I'm not upvoting because this doesn't really answer the question. However I'm not downvoting either because I personally found the information in this answer useful. –  jhocking Mar 11 at 15:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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