How to make sure a destroyed game object remains destroyed after application quit ?

Hi there, sweet people!

I have heart containers that you can pick up and they’ll increase your max health.

Problem is if you pick them up, quit the game, and open the game again, they’ll still be there. So you can just exploit that until you have the maximum amount of hearts.

I was thinking of using player prefs or static bools, but the thing is that there are more than 1 heart container. If I use player pref to destroy it upon loading, it’ll destroy them all.

The only solution I can think of is by creating a script for every single heart container… There must be a simpler way.

Oh, also, this behavior can’t be linked to the player max health or scene name, since some containers are hidden and he can miss it and come back in the future with a different health amount to pick it up.

Anyway, that’s it! Thanks in advance!

Hello Garien,

You could have a bool for each heart container in the save file, and when the game loads it only activates the ones that haven’t been collected so far. You can do a script witch checks if the heart container has been collected when starting the game and modifies the save file when you collect one.

Hope you find it usefull =)

1 Like

Sure is useful! I was thinking of doing something similar, but I wanted something more scalable, since there are heart containers, heart fragments, chests… Doing it all one by one will sure take a lot of time, but I guess it seems it’s the only way to go…

Yeah… I can’t think of something else…
You could use arrays, like… one for heart containers, one for chests,…
You can make a script that does all the work for you.

I wish you success with your game =)