Why do we need the Singleton code?

Hi Jayy,

When you load a scene, all objects in that scene get created. Assuming you have five scenes, and all of them contain a persistent MusicPlayer, you’ll end up with multiple persistent MusicPlayer objects in your scene when you loaded a few scenes. To avoid this, you make the class a “singleton”. The superfluous MusicPlayer objects will destroy themselves including their game object, which results in a pleasantly tidy Hierarchy.