Excluding 1 level from our Singleton

Hey there!
Does anyone knows if there’s a way to exclude our main menu scene from the singleton rule? i want the main menu to be the only scene in my game with different music… Thanks!!!

Hi Jerry,

What exactly do you mean by “exclude”? Do you want to destroy the object on which we called DontDestroyOnLoad? Do you want to prevent the method from being called?

Whatever your idea might be, you have to check in which scene you are. This can be done with SceneManager.GetActiveScene().name or SceneManager.GetActiveScene().buildIndex. You can compare the respective value with your own in an if-condition.

Did this help?


See also:

Hi nina! thanks! i think it would be better to destroy the object that is in existance, it is the first level on the build (0) and it is called MainMenu.

Did you manage to make your idea work?

This topic was automatically closed after 7 days. New replies are no longer allowed.

Privacy & Terms