hi there quick question, is there such a command in unity as Application.UnloadLevel(), or Application.CloseLevel() ?
i ask this because i have a main menu in my game, from the main menu you pick start level which is the Application.LoadLevel() command which loads my main game level.
I have a command in game which is on button “Esc” it uses Application.LoadLevel to go back to the main menu scene.
BUT when i go back to load my main game level from the main menu scene, the main game level is STILL running, so it creates two instances of everything in the scene on top of one another (ie when i exited the main game level it never unloaded the level assets, just loaded a different scene, keeping the game level running also)
is there a command to unload the game level (or any scene you leave) upon exiting the scene or entering a new one?
LoadLevel cleans out the old level, it won’t be running anymore for sure afterwards.
if something is still running you have stuff with “DontDestroyOnLoad” which you forgot to kill manually. They will not vanish until you destroy these game objects or close the application
1 Like
hmmm… it’s actually just my player character that keeps making instances of itself… nothing else now that i notice. but i don’t use DontDestroyOnLoad on the character anywhere i believe. it’s not an instantiated character either, it’s just set out in the scene with a camera and character controller on it.
hmm
hmmm no actually the background and the whole scene is still running when i enter… and it creates another player on top of the one running, both react to user input.
i’m just using a 3d text object with Application.LoadLevel(3) on the mouse up (3 being the main game scene) and in the main game scene i have a line of code that checks input on the “escape” key, and then runs Application.LoadLevel(1) to go back to the main menu. is that not the correct way to be doing it?
this is in a web player also if that makes a difference
When you go back to your menu scene, are there still instances of your player in the scene hierarchy? That would indicate it’s Don’tDestroyOnLoad() at work.
Other things to consider, are there two and only two players no matter how many times you go to the menu and back into the scene? That would indicate you actually have two copies of the player in your scene. Delete one and see what happens.
If it’s an ever increasing amount, if you can build an army, then the only other possibility I can think of is that you’re using LoadLevelAdditive().