Answered
0
0

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?

Thanks

  • You must to post comments
Best Answer
1
0

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);
    }
  • You must to post comments
0
0

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

  • renato.martinho@gmail.com
    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.
  • renato.martinho@gmail.com
    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?
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.