x


character doubles when returning to the main scene

hi. I would like to ask on how will I be able to avoid multiplying my characters after loading a level. My character will travel to scene0 to scene1. After finishing scene1 it will return again to scene0. But after it returns, it doubles... what do you think is the problem

more ▼

asked Feb 06 '12 at 05:00 PM

berting01 gravatar image

berting01
51 39 52 58

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

2 answers: sort voted first

You likely are instantiating your character in a script's awake or start function. The object this script is attached to is being destroyed and reloaded when you load the second scene, triggering the awake & start again. You have a lot of options for how to fix this problem. Either don't have the object that instantiates the character be loaded on every scene or check for an existing character before you instantiate, and don't instantiate it the second time.

more ▼

answered Feb 06 '12 at 07:42 PM

kevork gravatar image

kevork
415 1 2 4

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

I'd check with a script to see before the scene has loaded whether there is already a character there, and if so, delete it, and if not, just carry on- so this way you'll only have one.

more ▼

answered Feb 06 '12 at 05:19 PM

Fishman92 gravatar image

Fishman92
2.4k 101 113 128

will i be using Destroy()?

Feb 06 '12 at 06:52 PM berting01
(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:

x5087
x718
x66

asked: Feb 06 '12 at 05:00 PM

Seen: 394 times

Last Updated: Feb 06 '12 at 07:42 PM