Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Audio stops abruptly when loading new Scene

Discussion in 'Audio & Video' started by coska, Dec 12, 2022.

  1. coska

    coska

    Joined:
    Dec 8, 2022
    Posts:
    6
    Hello!

    Using Wwise with Unity:

    When loading a new scene in Unity, all audio is abruptly stopped, and resumes when the new scene has loaded.

    The object on Scene A is a AkAmbient Simple Mode with a Play event that plays a music track all over this "zone" (Scene).

    On that AkAmbient object I also have a Stop event (with a 3 second fade out) that should trigger on Destroy (leaving that zone).

    But when zoning, the music stops abruptly, Scene B is being loaded and when it's loaded, I can, for a brief moment, hear the fadeout from Scene A's music taking place.

    My gut feeling is that this issue is caused by the SoundBank being unloaded and hence kills all audio while loading the new Scene. There is only one SoundBank in this project at the moment, so unloading the SoundBank seems unnecessary. But even if I would use multiple SoundBank (in the future), I would need a smart solution for that scenario as well.

    I hope I can get some advice to get this issue cleared. Thanks!
     
  2. coska

    coska

    Joined:
    Dec 8, 2022
    Posts:
    6
    Solution found. I post it here in case someone has the same issue, it might help them.
    In the client.cs script, we made some changes and now it looks like this from line 222:

    Code (CSharp):
    1. protected override void OnDestroyEntity() {
    2. #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
    3.             if (this == mine) {
    4.             // If the client has an AkAudioListener then it is our character.
    5.             if (gameObject.GetComponents<AkAudioListener>().Length != 0) {
    6.                 if (Camera.main != null) {
    7.                     var cameraAkObj = Camera.main.GetComponent<AkGameObj>();
    8.                     if (cameraAkObj != null) {
    9.                         cameraAkObj.enabled = true;
    10.                     }