FadeOut on Scene Change

(Renato777) #1

I’m trying to fade out my music track (ambientSoundTrackTwo), which is spawned by an AudioControl script, as soon as a new scene is loaded. I’ve written the following code on my AudioControl.cs, but it doesn’t seem to be working:

void OnDestroy()
		ambientSoundTrackTwo.stop (FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
		Debug.Log ("Close Scene");

The Debug message is printed on the Console when the scene closes, though, so I guess the OnDestroy function is working.

Any ideas?


(Nicholas Wilcox) #2

If by not working you mean it stops without fading out: have you added an AHDSR to the fader on the master track?

(Renato777) #3

Yes, I have added an AHDSR to the master track. The fade-out is working when I preview it on the FMOD Editor by holding the stop button, so I reckon there’s something wrong in my code.
Also, on Unity, if I preview the event on the Inspector window, as I press Stop, it doesn’t fade out. I’m not sure if that “stop” command is the same as the Non-Immediate Stop available on the Fmod Editor.

(Renato777) #4

I guess maybe the problem is that the FMOD_Listener, which is attached as a component in the Camera Prefab, is being destroyed and spawned back again. Any ideas on how to avoid this?

(Renato777) #5

Ok, just found out the solution to this… It was quite simple actually…

I just had to call the “DontDestroyOnLoad” function on the FMOD_Listener script, so it wouldn’t be destroyed between scene changes.

void Awake()
		DontDestroyOnLoad (this);