I am making a very simple 2D game, but I have came across a problem; I have searched endlessly to find answers to, as to why I am here. But I am having trouble with my scenes. I have scripted scenes to change back and forth (without any issues), however, say I go from one scene to another and [having incorporated] a back button to the previous scene; both scenes have collided. Like the background from the next scene finds its way back to my previous one. And any actions I have made as a player in the first scene; like a pop up window I had closed, reopens itself when I go back.
So, as I was researching some would speak on: dontdestroyload and playerperfs as a solid reason to fix that issue. As someone new to the coding world, and before I proceed any further, I just want to make sure that those make scripting components is what is needed to correct my current problem.
Any help would be much appreciated.
Thanks
You need to positively identify what the problem is before you can reason about how something fixes it.
Scenes are tricky because they don’t load until the END of the current scene, then the current scene unloads and the new scene is running next frame.
One handy way to debug glitches between scenes is to pause the editor with Debug.Break() when you begin the new scene change, then single-step, studying what is in the scene each frame.
1 Like
Not necessarily.
dontdestroyonload is designed for essentially allowing gameobjects and the components attached to them to float around. Usually best used with singletons.
PlayerPrefs is best used for basic data storage. Like the name says, “Preferences” such as volume level, resolution settings, etc.
What you’re describing doesn’t seem to make sense. What is your loading code like? Are you doing Additive loading? Is this popup window open by default in the first scene?