Application.LoadLevel problem

If I use Application.LoadLevel to restart my current scene, it doesn't seem to "reset" everything. I only have one "DontDestroyOnLoad" object in the scene, and if I reload the level from within the level script, this gets duplicated, and the code complains about me trying to "access transforms which have been destroyed". The only way I can get round this is to load up an empty scene and then re-load the level I was in from there, but this is clumsy and takes longer than it should.

Any ideas on this? What am I doing wrong?

Two quick comments:

  1. If you're reloading the scene that has the object flagged as 'don't destroy on load' in it, then a new copy of that object will be created every time the scene is loaded. (In other words, the fact that you flagged the object as 'don't destroy on load' doesn't prevent that object from being created again when the scene is reloaded.) If you only want one copy of that object, you'll need to set things up differently (for example, include the object in a 'startup' scene that's only loaded once).

  2. Regarding the 'accessing transforms that have been destroyed' problem, be aware that any references the 'don't destroy on load' object is holding to game objects or components in the scene will become invalid when the scene reloads.

hi i haveing problem then i use appkication.loadlevel in my script it’s automatecky loads next lvl from my main meniu lvl my script looks like this were i added application.loadlevel

private void DisplayButton() {
if(GUI.Button(new Rect(Screen.width/ 2 - 50,STAT_STARTING_POINT + (10 * LINE_HEIGHT),STAT_LABLE_WIDTH,LINE_HEIGHT),“Create”)); {
GameObject gs = GameObject.Find(“_ _gamesettings”);
GameSettings gsScript = gs.GetComponent();