Uncover the Simple Trick to KEEP MUSIC PLAYING Between Scenes!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello dear friends.  In this video we will learn how to carry background music to the next scene. In the previous video we have added the Finish point to the game. And when the player reaches the finish point, the level is completed and the next level is loaded. But as you can see, the background music starts from the beginning when the scene changes. I want the music to continue when the scene changes. I want to quickly show you how you can do this. Ok let’s get started. First , let's take a look at current Audio Management system. We have 2 audio source  component for music and SFX.  And we have Audio Manager  script to control music and SFX. And the Audio Manager object exist in all scenes. So when a new scene is loaded, the music is reload and restart. If we have one source of sound and carry it between the scenes, we will reach our goal. Let’s do it. I will delete the audio manager in level 2 and level 3. Start the game in this case. The Music plays at Level 1. But music does not play at Level 2. When loading a new scene the objects of the previous scene are destroyed, And the objects of the new scene are created. I want Audio Manager object to be moved to active scene. This way the music will continue to play. Open the AudioManager script. I’m gonna use DontDestroyOnLoad method to the AudioManager object is not destroyed. Save the script and go back to unity. Start the game. Here you can see the objects that will not be destroyed in the transition between scenes. level 2 is loaded and the music is still playing. the level 3 scene is loaded and the music is still playing as we want. As you can see the music continues to play between scenes without returning to the beginning. So what happens if there is the  AudioManager object in other scenes?  I will copy the AudioManager  object to other scenes.  Start the game. Everything is fine on level 1. but when we go to the level 2, the music plays from two places and the music overlap. I’ve created static instance from the AudioManager script. If this instance has not been created before, let the instance be this object. And Do not destroy this object. if this instance was created before, Destroy this object. Ok save and go back to unity. as you can see the AudioManager object exists at both level 1 and level 2. Start the game again.  We went to level 2.  and as you can see there is  still 1 AudioManager object. If you used the DontDestroyOnLoad  method on an object, all components and child objects of that object are not destroyed. scene controller script is present in the game manager object. And the scene controller script contain DontDestroyOnLoad method. so the game manager will not be destroyed. If I make the Audio manager object the child object of the game manager object the Audio Manager is not destroyed either. So I don't need these codes.  delete audio manager in level 2. Open level 1 scene. And drag and drop the AudioManager object to the GameManager object. as you can see the Audio Manager object has become the child object of the game manager object. Start the game. I hope the video useful for you.  Thanks for watching. See you in the next video.
Info
Channel: Rehope Games
Views: 20,809
Rating: undefined out of 5
Keywords:
Id: xswEpNpucZQ
Channel Id: undefined
Length: 4min 41sec (281 seconds)
Published: Sat Mar 25 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.