# Could not stop the sound instances when transiting from another scene

**URL:** <https://qa.fmod.com/t/could-not-stop-the-sound-instances-when-transiting-from-another-scene/20438>\
**Category:** Unity\
**Tags:** unity\
**Created:** [July 19, 2023, 3:04am UTC](https://qa.fmod.com/t/could-not-stop-the-sound-instances-when-transiting-from-another-scene/20438 "2023-07-19T03:04:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![32nguyen](https://avatars.discourse-cdn.com/v4/letter/3/3e96dc/32.png) [@32nguyen](https://qa.fmod.com/u/32nguyen)\
**Post date:** [July 19, 2023, 3:04am UTC](https://qa.fmod.com/t/could-not-stop-the-sound-instances-when-transiting-from-another-scene/20438/1 "2023-07-19T03:04:36Z")

</div>

Dear,

I’m having trouble stopping the sound instances using OnDestroy() when transitioning from the level scene to the main scene. Interestingly, it works fine when transitioning from the main scene to the level scene. Although the OnDestroy() function is executed, the stop and release commands don’t seem to work for some unknown reason. Could someone please take a look at my code and provide some guidance?

```auto
void Update(){  
    PlayAirWind();
    PlayVehicleSound();
}

void OnDestroy(){ // transit to other scense need to remove the instance that created on Start()
    wind.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
    wind.release();
    vehicle.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
    vehicle.release();
    // enemyZone.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
    // enemyZone.release();
}

void PlayAirWind(){
    FMOD.Studio.PLAYBACK_STATE fallState;
    wind.getPlaybackState(out fallState);
    if (!playerController.isOnGround){
        wind.setParameterByName("Height", playerController.relativeHeight);
        if (fallState != FMOD.Studio.PLAYBACK_STATE.PLAYING){
            wind.start();
        }
    }
    if (playerController.isOnGround || playerController.moveSpeed == 0){
        wind.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
    }
}

void PlayVehicleSound(){
    FMOD.Studio.PLAYBACK_STATE vehicleState;
    vehicle.getPlaybackState(out vehicleState);
    if (playerController.vehicleOn){
        vehicle.setParameterByName("Height", 20);
        if (vehicleState != FMOD.Studio.PLAYBACK_STATE.PLAYING){
            vehicle.start();
        }
    } else {
        vehicle.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
    }
}

```

I do not know where I did wrong. Thanks.

---

<div class="post-metadata">

**Author:** ![Connor\_FMOD](https://yyz2.discourse-cdn.com/flex036/user_avatar/qa.fmod.com/connor_fmod/32/3685_2.png) [@Connor\_FMOD](https://qa.fmod.com/u/Connor_FMOD)\
**Post date:** [July 20, 2023, 12:01am UTC](https://qa.fmod.com/t/could-not-stop-the-sound-instances-when-transiting-from-another-scene/20438/2 "2023-07-20T00:01:38Z")

</div>

Hi,

I would suggest logging the result of the `stop()` and `release()` functions, most FMOD functions return and `FMOD.RESULT` ([FMOD Engine | Core API Reference - Common](https://fmod.com/docs/2.02/api/core-api-common.html#fmod_result)) which can aid in debugging why functions aren’t behaving as expected:

```auto
FMOD.RESULT result = wind.stop(FMOD.Studio.STOP_MODE.ALLOWFADEOUT);
if (result != FMOD.RESULT.OK)
{
    Debug.Log(result);
}

```

Could you please also change your FMOD `Logging Level` to `Warning`  
 ![image](https://canada1.discourse-cdn.com/flex036/uploads/fmod/original/2X/3/3064d82d400c11f18c54d4f8aa426a6f5a9ea777.png)  
This will log any other errors that may be occurring.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![32nguyen](https://avatars.discourse-cdn.com/v4/letter/3/3e96dc/32.png) [@32nguyen](https://qa.fmod.com/u/32nguyen)\
**Post date:** [July 20, 2023, 3:21pm UTC](https://qa.fmod.com/t/could-not-stop-the-sound-instances-when-transiting-from-another-scene/20438/3 "2023-07-20T15:21:17Z")

</div>

Thanks, it really helps to force me find the bug at another script which I did not pay attention as before. The above code actually works properly.
