Save Progress between two scenes in Unity (2D Platformer),Save Progress in Unity 2D Platformer

I’m still struggling to figure out how to code this in Unity. I have a button (which is it will change to scene 1 to scene 2, vice versa) then in scene 1 I walk towards the middle of the level already, but if I press the button it will change to scene 2 then my player resets into the start of the level, I want it to be in the middle of the level in scene 2, I want it somehow save my progress in scene 1 and will input into the scene 2. Because my concept is I have a level in scene 1 that my player cannot pass through an obstacle, then if i press the button (which is the scene change) ill design a level into scene 2 that there’s no obstacle into it, and the player can pass through.

Hi!

You can try using DontDestroyOnLoad(). Normally any gameobjects in a scene get destroyed when you load a new scene, but if you call DontDestroyOnLoad on them, they’ll stay exactly as is.

Mind you this does have some complications, as it will even persist into e.g. your main menu, and you will need to properly handle your player in situations like those. (Do some searching on singletons if you’re interested.)


Another perhaps simpler alternative (and my recommendation) is not to change scenes at all. If you keep e.g. your day level and night level in the same scene and simply disable one and enable the other when you press this button, as long as the player is not a child of either of these levels, the player will remain unaffected as the level changes!

It should be clear that in this scenario, the player won’t suddenly appear in your main menu, as it would with DontDestroyOnLoad.

Hope this helps!