- Home /
Switching Levels, Instances get destroyed?
When you swap over a level, how do you go about carrying over data or instances?
Such as, if I have a screen that allows players to enter in their name and add in skill points. After they are done they hit the create button which brings them to level one. Since the instance of the player existed on the screen that lets them add their name and skill. WHen you hit create, do all instance get destroyed?
Answer by superventure · Jan 22, 2011 at 05:23 AM
I'm not exactly sure how you're executing this, but did you try adding
DontDestroyOnLoad (this);
on your player?
Answer by Bunny83 · Jan 22, 2011 at 05:28 AM
Simple ;) DontDestroyOnLoad(AGameObject) that would mark this object so it don't get deleted at level loading. If you use this on a GO, all child objects and scripts attached will remain too. Normally you have some kind of manager scripts that care for such stuff. I always use a GO that i call "App" and this one has a script like:
//JS function Start() { DontDestroyOnLoad (this); }
//C# void Start() { DontDestroyOnLoad (this); }
ps. If you use DontDestroyOnLoad on a component (like i did above, i used it an the script component) the GameObject is also "saved" because a component can't "live" without an GO ;)
Your answer
![](https://koobas.hobune.stream/wayback/20220613100539im_/https://answers.unity.com/themes/thub/images/avi.jpg)