I’m a UX guy, but out of necessity I’m doing some Unity work, so please bear with me…
The scene I’m working in constantly spams the message “There are no audio listeners in the scene. Please ensure there is always one audio listener in the scene”. If I add a dummy camera with an Audio Listener, I then get “There are 2 audio listeners in the scene. Please ensure there is always exactly one audio listener in the scene”.
I know a couple of things…
This happens because our camera is created programmatically, with an audio listener.
This will not affect the non-development build in any way.
It still bothers me and I feel the need to “fix” it.
That being said, what is the recommended action here? Is there ANY thing I can do that isn’t too hacky?
If I understood well, your problem is that it takes a bit of time to create the camera, and meanwhile, sounds are being sent out, with nobody to listen, right?
There’s A LOT of things you could do. Here you go:
- Add a “dummy” gameobject with an audio listener that’s there from the very start. When the camera appears, destroy it.
- Alternativelty, put the audio listener in an empty gameobject which is there from the start (with ONLY an audiolistener). Remove the audiolistener from the camera. After the camera is created, make the object the camera’s child, and set it’s local position to zero.
- Or, just create the camera before you start playing any sounds.
Don’t make every object check if there is a camera before producing a sound. If you’re new to Unity, you’re likely going to choke the processor unnecessarily.
Hope it helped!
So I know a little more now and I also have a solution.
We have a static camera that shows the login screen. Once you login, it loads the player camera dynamically. The static camera had the Audio Listener disabled (thus the “You have no audio listeners”…). If I enable it, then I would get the “You have 2 audio listeners” error once the player camera was instantiated. To resolve this, I simply destroy audio listener on the static camera on player spawn, like so: