x


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?

more ▼

asked Dec 07 '10 at 11:51 AM

S7ARBVCK gravatar image

S7ARBVCK
80 6 8 8

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Dec 07 '10 at 03:33 PM

Jesse Anders gravatar image

Jesse Anders
7.3k 7 17 48

(comments are locked)
10|3000 characters needed characters left

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,LINEHEIGHT),"Create")); { GameObject gs = GameObject.Find(" _gamesettings"); GameSettings gsScript = gs.GetComponent(); gsScript.SaveCharacterData(); Application.LoadLevel(1); } }

more ▼

answered Jan 22 '12 at 03:21 AM

edvinaszz gravatar image

edvinaszz
1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x84
x18

asked: Dec 07 '10 at 11:51 AM

Seen: 2444 times

Last Updated: Jan 22 '12 at 03:21 AM