- Home /
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.
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.
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.
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.
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!
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).
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)
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
Follow this Question
Related Questions
Help with loading a scene,Help changing scenes (C~ script) 1 Answer
DontDestroyOnLoad cancelling when Main Menu is open 1 Answer
bool doesn't change?? 0 Answers
Distribute terrain in zones 3 Answers