Question about the singleton

Hi Shaktillar,

The job of our “singleton” is to keep our MusicPlayer game object “alive” if we load another scene. While it is true that scene 0 gets destroyed when we load a new scene, our MusicPlayer will continue to exist in the new scene.

When we load scene 1 and there is another MusicPlayer in that scene, we would have two MusicPlayer objects for a brief moment. The Awake() and the Start() method of our persistent MusicPlayer will not get called again. Only Awake() and Start() of the new MusicPlayer object will get called. And that’s the reason why our “singleton” does not destroy our “first” MusicPlayer but the new ones only.

Did this make sense? :slight_smile:


See also: