# FadeOut on Scene Change

**URL:** <https://qa.fmod.com/t/fadeout-on-scene-change/11847>\
**Category:** Unity\
**Created:** [March 9, 2015, 11:14am UTC](https://qa.fmod.com/t/fadeout-on-scene-change/11847 "2015-03-09T11:14:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Renato777](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@Renato777](https://qa.fmod.com/u/Renato777)\
**Post date:** [March 9, 2015, 11:14am UTC](https://qa.fmod.com/t/fadeout-on-scene-change/11847/1 "2015-03-09T11:14:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nick1](https://avatars.discourse-cdn.com/v4/letter/n/47e85d/32.png) [@nick1](https://qa.fmod.com/u/nick1)\
**Post date:** [March 10, 2015, 11:42pm UTC](https://qa.fmod.com/t/fadeout-on-scene-change/11847/2 "2015-03-10T23:42:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Renato777](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@Renato777](https://qa.fmod.com/u/Renato777)\
**Post date:** [March 11, 2015, 11:16am UTC](https://qa.fmod.com/t/fadeout-on-scene-change/11847/3 "2015-03-11T11:16:16Z")

</div>

> [@](#):
>
> If by not working you mean it stops without fading out: have you added an AHDSR to the fader on the master track?

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.

---

<div class="post-metadata">

**Author:** ![Renato777](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@Renato777](https://qa.fmod.com/u/Renato777)\
**Post date:** [March 11, 2015, 6:37pm UTC](https://qa.fmod.com/t/fadeout-on-scene-change/11847/4 "2015-03-11T18:37:33Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Renato777](https://avatars.discourse-cdn.com/v4/letter/r/65b543/32.png) [@Renato777](https://qa.fmod.com/u/Renato777)\
**Post date:** [March 19, 2015, 11:53am UTC](https://qa.fmod.com/t/fadeout-on-scene-change/11847/5 "2015-03-19T11:53:04Z")

</div>

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);
	}
```
