Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 KBurchfiel · Jun 02, 2016 at 08:48 AM · c#scripting problemsceneplayerprefsdontdestroyonload

How to stop objects you picked up from reappearing when you go to another level and return

I'm very new to Unity, but I would like to create a game in which you go to different scenes (levels) and collect lots of the same item, which is then used to open new stages of the hub world. The concept is inspired by Banjo-Kazooie, where you collect lots of notes to open different stages of Grunty's Lair. However, I do not intend to make a BK clone; I refer to BK below simply because it's a well-known reference.

I've figured out how to transfer from one scene to another and back, but the problem I'm running into is that when I pick up all my items in Scene 1, then go to Scene 2, and then return to Scene 1, the Scene 1 items have all reappeared. (That means that instead of having to go to all the levels, the player could just switch between scenes, pick up the respawning items, and win the game easily. The BK equivalent would be getting all the notes in Mumbo's Mountain, leaving, coming back, and then recollecting all the notes so that you have 200. Note: because my score also resets in between levels, that isn't necessarily the problem right now--but it will be once I figure out how to preserve my scores.

  1. I'm wondering if there is a way to stop those Scene 1 items from reappearing (similar to how notes collected in Banjo-Tooie never come back). One comment suggests that DontDestroyOnLoad would not help, since the pick-up items would still come back.

  2. One possibility would be to make the pickups specific to each level. For instance, to open Door B in the hub scene, you would need to collect 50 Door B points in Scene A. Door A points, Door C points, Door D points, etc. would do nothing. Once you have 50 Door B points, Door B would be destroyed. You wouldn't gain anything by picking up 10 Door B points, then leaving/returning, because your Door B point score is automatically reset to 0. But again, once I go back from Scene A to the hub scene, I would lose all my Door B points and Door B would be back. But if I could simply preserve my number of Door B points from Scene A to the hub scene, that would work fine.

  3. In Banjo Kazooie, the notes do come back, but if you collect 80 notes in Mumbo's Mountain, leave, return, collect 75 notes and come back, you would only have 80 notes (not 155). The game only preserves your high score for each level. Would there be a way to program that into my game? That way, recollecting the notes wouldn't accomplish anything for the player, unless they collect more notes than they did before.

  4. I'm very tempted to only use one big scene and teleport the player from level to level within that scene. If I have 5 or 6 different levels, would that drag the game down if my art stays pretty basic?

THANK YOU in advance for your help!

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 Eudaimonium · Jun 02, 2016 at 11:25 AM 1
Share

I have written a tutorial series dealing with that exact problem, see here:

http://www.sitepoint.com/saving-data-between-scenes-in-unity/ http://www.sitepoint.com/saving-and-loading-player-game-data-in-unity/

And the last one which you will find useful, which deals with saving world object states: http://www.sitepoint.com/mastering-save-and-load-functionality-in-unity-5/

I hope it helps. If you have any questions in regard to that particular system, feel free to send a message on the forums (it's called Conversations I think).

1 Reply

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

Answer by Hellium · Jun 02, 2016 at 08:48 AM

You have a very simple problem : Persistent data management.

There are many ways to solve this. Store the info about collected objects in :

  • SQL Database (avoid if you only have one type of object to collect, don't go into this for one sql table only)

  • Files : Simple text / XML / JSON / ... (A little bit tricky, but not that much)

  • Scriptable objects : Pretty simple to use

  • PlayerPrefs (avoid for big volume of data)

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 Cyborg_X · Jan 05, 2019 at 10:07 PM 0
Share

Hi sorry I know this post is a few years out of date but I was wondering how would I go about doing this for points.

I have it so they need 10 overall points to access the secret level but at the moment you could just do the first level 10 times to do it, how would I make it so the points would stay destroyed? Thanks!

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

6 People are following this question.

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

Related Questions

Help with loading a scene,Help changing scenes (C~ script) 1 Answer

How do I save the high score from the game scene onto the main menu scene using PlayerPrefs and Dontdestroyonload? 3 Answers

DontDestroyOnLoad cancelling when Main Menu is open 1 Answer

bool doesn't change?? 0 Answers

Distribute terrain in zones 3 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