I am making a 2.5D Platformer. I have most of my mechanics finished except to properly reload levels. I have a shop portal in my platformer where the player can collect coins, enter the portal, and buy new abilities. When they step into the portal, the shop scene is loaded. I have DontDestroyOnLoad for singleton objects like my player, HUD, musicPlayer, etc, and they are loaded with the shop as well. I have a leave button inside the shop that is supposed to reload the level they were just in before they entered the shop. The problem is when I reload the level it reloads from the beginning of course, and all the coins and enemies are back again.
I need advice on how to setup checkpoints for reloading a scene from the state it was before I entered the shop. I tried things like making a prefab of the shop and loading it when I need it then destroying it, but it really makes a mess and I think there is a better way to do this. Any help appreciated!
if I understand what you are trying to do, all you need is in the Start section of the script that is not destroy make a check if the script is already on the scene, and if it is, Destroy the current one, that way every time the level is loaded it will only keep the old copies of the game object
and that way you can make some kind of game object that keeps the players progress or last visited checkpoint
I hope i explained it right… my English isn’t that great
So you said to put a DontDestory on the level gameObject? I have an empty object named Level that holds all the gameObjects in the level. I’ll try putting a DontDestroyOnLoad on the empty “Level” object!
Using iPickle’s idea, you need to keep your “destroyed” game objects in the scene (maybe turn off their colliders and renderers) so they’ll be detected in the check.
If you don’t want to do this, you could serialize the level using something like Easy Save (or write your own). This also lets you save and load games.
If you don’t want to serialize, you could add a script to every changeable game object. The script can record changes to the game object (maybe to PlayerPrefs if you don’t have a lot of them). When the game object starts, the script can read those changes and apply them.
But if you only need the level to stick around during the current gameplay, don’t reload it. Just deactivate it while you’re in the shop, and reactivate it when you leave the shop.