Restarting the same scene with different active objects

Hi all,

I am trying to implement a checkpoint system for the top-down shooter game. The game consists of different spawner game objects which get activated or deactivated when some conditions are met. For example, the game starts the first spawner game object active and it gets deactivated when 30 enemies are destroyed, which activates another spawner object, and when 40 more is killed second spawner game object deactivates, and a third spawner game object gets activated, and so on.

Now what I try to implement is that if the player dies before reaching the third spawner, the scene restarts, but this time, I want the first spawner game object to be inactive(since the player already beat that section) and the second one to be active instead(because the player couldn’t beat the second wave)

I tried some bools to mark the progress of the player(if the player beats the first wave a boolean gets triggered) and created methods activating and deactivating the necessary game objects according to the boolean but couldn’t manage to achieve what I want.

I don’t want to litter here with my lengthy code since first I want to ask if this is even possible? Can you restart/reload a scene with SceneManagment’s LoadScene method, and would that scene load with different game objects activated? (You start the game gameObject1 is active-gameObject2 is inactive, after some progress the player dies, restart the scene with LoadScene, and the scene loads with inactive gameObject1 and active gameObject2)

I could set up different scenes with my desired preferences, as in, in one scene gO1 starts active, and in another gO2 starts active but this feels like a bad design probably cause I would end up with 5-6 scenes just for the first level.

I am sorry for the long post but It was a bit hard for me to describe what I wanted and asking. Thanks in advance for the ideas and pointer in the right direction.Cheers…=)

Hey all again,

After a bit of thinking I figured it out. I created a method with switch and case and fine-tuned what I want active and when I want them active and placed them under cases. Then called this method on awake. I also created checkpoint triggers with a method and tracked some game objects which start deactivated but activates when I want to place my checkpoints in time which is called in Update. When they get activated an int called checkpointIndex takes values like 1-2 (default is 0)which is also the index that I use for switch-case. Then I also saved this value with PlayerPref and called this right before switch-case to update the checkpointIndex. Lastly, I called LoadScene when the player dies. Also, I created an OnApplicationQuit method for deleting the saved index data which I will also add to the method that changes the level. In this way, it will only store the data for the duration of the level. So maybe this will help somebody…=)
Cheers…=)

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms