Reload a scene, but with different values

Hello. I’m very new to Unity, so I don’t know what I don’t know, yet. Here’s what I’m trying to do: I have this main scene in my game called “Level”. As you play, I want to be able to load this same scene over and over again, but it’ll be slightly different each time. For example, when you load it the first time, you only have to kill 3 enemies, but when you load it the second time, you have to kill 6. Just using this as a made up example. I thought I could get away with it by doing this:

       void Update() { //in my Level.class
       if (IsLevelFinished()) {
         SceneManager.LoadScene("Level");
         levelStatistics.totalEnemies = 6;
       }

But this isn’t working. The whole scene reloads again, but the levelStatistics has a totalEnemies of 3. It has a total of 3 because that’s what I have it set to in the Unity editor. In other words, the value I have on the unity editor is overriding the one I’m setting manually in my script.

How do I get around this? I’d like to reload the scene with slight variations from its defaults.

If you have only one scene at all times, I highly recommend that you create an Initialize() method or something like that and set up the start positions, enemies, etc in there, so when you restart the level you don’t reload it from the start but you just reconstruct the initial state.

Otherwise:

Well, I will for a brief period. But then my next iteration will be to have a “menu” between levels where you can buy upgrades. I imagine that “menu” will be its own scene, but honestly, I don’t know why it would be better to use a new scene for the upgrade menu vs re-initializing the level.

Thanks for the vid, I’ll watch it now.

Throw the data on something persistent. A ScriptableObject works well. Then each time you load the level, increment the numbers before using them.

Interesting suggestion. Ironically, that video doesn’t suggest this as a solution to the problem, but the next vid they have teaches about ScriptableObject.

I found this video and I think it could be used to achieve this, too:

And here’s a way that’s simpler than the previous video: