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
1
Question by superventure · Dec 01, 2010 at 06:19 AM · sceneloadlevel

Character duplicates herself when re-entering the home level

Hello- so I just applied this script to a general object in the home level and set it as a trigger

function OnTriggerEnter(other : Collider) { Application.LoadLevel("scene 2"); }

and made another level with a another general object the same way to go back to the home level.

I also put this on the player, a npc that follows her throughout the game, and the main camera. I deleted the main camera in the second level to keep the one from the home level.

function Awake () { DontDestroyOnLoad (this); }

The player, npc, and camera transport perfectly to the second level, but when I hit the object in the second level to go back home, the player, npc, and camera, duplicate each time! How do I make sure the game retains the original player, npc, and camera no matter which level I enter or re-enter? Also, how do I allow any item they might holding (and only that item) to transport with the player or npc if they are holding it?

Thanks for any help

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Rennat · Dec 01, 2010 at 09:29 AM

The way I handle this kind of situation is to have an extra scene with just the player (or object that needs to persist through scene loads)

What you have

  • 2 scenes: Scene A and Scene B.
  • Scene A has a Player and the environment.
  • Scene B just has the environment.
  • When Scene A loads it creates the Player and tells it DontDestroyOnLoad.
  • Scene B is loaded and the Player comes along for the ride.

My approach

  • 3 scenes: Scene Loader, Scene A, and Scene B
  • Scene Loader has a Player and a script to load the next scene
  • Scene A and Scene B just have the environments
  • When Scene Loader is loaded it creates the Player and tells it DontDestroyOnLoad then immediately loads Scene A
  • Scene A is loaded and the Player comes along for the ride.
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 superventure · Dec 01, 2010 at 10:33 PM 0
Share

This worked liked like a dream! $$anonymous$$akes sense too. Thank you so much for your help!

avatar image
0

Answer by Zu01 · Dec 01, 2010 at 10:33 AM

That, or you could try useing one gargantic scene =). That is exactly what I do sometimes.

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

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

No one has followed this question yet.

Related Questions

Random level select 1 Answer

Load Scene 1 Answer

Input.GetMouseButton on multiple objects 1 Answer

Load level after Image Sequence 0 Answers

checkpoint level please 2 Answers


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