So in my previous project I did all my game audio using Garage Band, I thought it came up pretty good, but one thing I hate the most is how the audio stops when you jump from one scene to the next one, I found a lot of articles about having a singleton audio source but having had any luck or probably need to try other ways. Have anyone done anything like that? To me audio is one of the key aspects of a game and I want a clean background music, fun music, and non-interruptive experience for my players.
Well one way to deal with this is… how about you use only one scene for all of your levels? I still haven’t decided for myself which way I want to go… either one scene per level, or one scene for all levels. There are pros/cons to each, mostly in regards to performance.
hehe That’s another decision I’m trying to make, right now I have a Menu Scene and a Game Scene, I do keep all my levels in the Game scene however when going from menu to game it stops the audio, I may end up just lowering the volume so it does some kind of a fade effect with the audio and then play another song in the game.
Create a single gameobject that handles the audio and allow it to persist scene loading via DontDestroyOnLoad(this); and handle all the audio via scripting and if wanted you can lerp the audio volume for a smooth transition.
If you do that I would recommend, the one scene route, that you have a switch statement controlling all the elements. I’m sure there’s a better way but you could make a single gameobject, preserve that and control it runtime via script.
Excellent guys thanks, ok sorry for asking so the DontDestroyOnLoad would work this way?
In my Menu scene I have a Menu.cs file, based on what you said I will add this DontDestroyOnLoad(this); to my Awake() method? This would be the object containing my AudioSource correct? then from My second scene Game.cs how do I access my prev object? Would it still be available in my hierarchy? can I do something like GameObject.find(“MyAudioObject”)?
I’m curious though if line 9 (where you destroy an old instance) would serve to interrupt the music that is playing? @dilmer please let us know how it works out once you get it going
Line 9 only get’s called if you accidentally create a second SoundController, which should actually never happen.
Even so, all it does is destroy the new Instance while the original is left untouched. The music shouldn’t be interrupted.