Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by berting01 · Feb 06, 2012 at 05:00 PM · scenelevels

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Feb 08, 2014 at 07:21 PM 0
Share

Tell us how the "Player" got into Scene 0 to start with. Is it just a GObj in your Hierarchy when the scene is loaded, is it a prefab one of your scene scripts is instantiating, etc. I guess it's also worth clarifying does your 'player' have a bunch of custom classes/scripts/variables associated with it (or is it just a happy cube)?

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by HolBol · Feb 06, 2012 at 05:19 PM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image berting01 · Feb 06, 2012 at 06:52 PM 0
Share

will i be using Destroy()?

avatar image
0

Answer by kevork · Feb 06, 2012 at 07:42 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by nightbane30 · Feb 08, 2014 at 07:17 PM

If I were you, I would use destroy. Also, make sure you don't have DontDestroyOnLoad on the player during the scenes, as this would cause it to duplicate itself in the next scene.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image getyour411 · Feb 08, 2014 at 07:17 PM 0
Share

I disagree. It's likely there are many scripts and variables on Player that could easily have changed in scene 1 (paid gold for item, level'd up, earned XX points, whatever) and if we destroy on return to scene 0? Bad mojo. Player is usually going to have DontDestroyOnLoad

The real issue is how the permanent "player" got into scene 0 in the first place

avatar image Owen-Reynolds · Feb 08, 2014 at 07:30 PM 0
Share

It does sound like a DontDestroyOnLoad problem. If you use it, you have to think carefully about how to spawn only once. One solution is to use Destroy in Awake if you see you're an extra player. Or, don't start the player in any scene, but have each master "sceneScript" instantiate if needed. Or put the player in the intro scene, which you can never go back to.

getyour: I sometimes find I have to create the player differently for some levels -- rigidbody for the space level, charController for land, diff movement script for the boardGame-style level… . Sometimes having the player naturally be born/die with the level, and a dontDestroyOnLoad playersStats object (for gold, level…) is easier.

avatar image nightbane30 · Feb 10, 2014 at 12:13 PM 0
Share

True. Or, couldn't you just duplicate Scene0 but remove the player gameObject, and just have everything else entirely the same? It's not the most memory saving way, but it would work.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Selecting scene for your main menu 1 Answer

Problem with click to display information 1 Answer

Save game objects to new scene 0 Answers

How to load a scene on collision 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges