Two AudioListeners

There are 2 audio listeners in the scene. Please ensure there is always exactly one audio listener in the scene.

Hey there! I’m loading a second scene additively through SceneManager, transferring over an object from the first scene to the second, then unloading the first scene. However, both scenes have an AudioListener of their own so I get the above notification which is rather irritating, so I tried deleting the AudioListener from the first scene just before loading the second scene, but then I got a similar error but saying I have no AudioListeners, despite how this update was made in the same frame. How can I get rid of this notification effectively? Thanks!

EDIT: I could remove all AudioListeners from each scene and move the one from scene 1 to scene 2 every time I add a scene additively, but this would take a lot of effort and wouldn’t allow me to test in the second theme without first loading through the first scene, so I want to avoid this if possible

My scene loading works like this:

  • I non-additively load my “Loading” scene, which has an AudioListener in it. Unity destroys the old scene and loads the new scene.
  • After the “Loading” scene is loaded, I start additively loading the new scene. I use ‘allowSceneActivation = false’ to avoid activating the new scene immediately.
  • I then allow activation of the new scene. When it’s done, I disable the audio listener in the “Loading” scene.

Here’s the code:

var actualSceneAsyncOperation = SceneManager.LoadSceneAsync(GlobalStateDirector.Instance.CurrentSceneDefinition.SceneName, LoadSceneMode.Additive);
actualSceneAsyncOperation.allowSceneActivation = false;

while (actualSceneAsyncOperation.progress < 0.9f)// Unity's Magic number, meaning that it's essentially completed, just not activated.
{
    yield return null;
}

actualSceneAsyncOperation.allowSceneActivation = true;

yield return new WaitUntil(() => actualSceneAsyncOperation.isDone);

loadingSceneController.GetAudioListener().enabled = false;

This seems to do the trick as far as not getting the error amount multiple audio listeners.

2 Likes

That is so smart actually, I’m trying this out. Thanks so much!

It works like a charm, thank you! My final code (including a loading animation):

AsyncOperation sceneToLoad = SceneManager.LoadSceneAsync(dataClasses.SpawnInformation.directedScene, LoadSceneMode.Additive);
        sceneToLoad.allowSceneActivation = false;

        while (sceneToLoad.progress < 0.9f)
        {
            slider.GetComponent<Slider>().value = sceneToLoad.progress;

            yield return new WaitForSeconds(slideMinTime / increments);
        }

        slider.GetComponent<Slider>().value = 1f;
       
        for (int i = 0; i < increments; i++)
        {
            slider.GetComponent<Slider>().value -= 1f / (float)increments;

            yield return new WaitForSeconds(slideMinTime / increments);
        }

        sceneToLoad.allowSceneActivation = true;

        currentListener.enabled = false;

        yield return 0;

        SceneManager.UnloadSceneAsync("LoadingScene");
1 Like