- Home /
2 Audio Listeners in the Scene (C#)
I have it set so that the player can change between two cameras (first person perspective and third person perspective) by hitting a keybind. So, I have two cameras in my scene. I get a notification in the console that says:
"There are 2 audio listeners in the scene. Please ensure there is always exactly one audio listener in the scene."
In order to combat this, I tried the following code in the Start () method of the CameraControllerScript, which belongs to an empty called CameraController. The CameraController is the parent object of both cameras, and I attached their scripts to that Controller.
Code: public class CameraControllerScript : MonoBehaviour {
bool isFPSCameraActive = false;
bool isThirdPersonCameraActive = true;
FirstPersonCameraScript fpsCamera;
ThirdPersonCameraScript thirdPersonCamera;
void Start () {
fpsCamera = gameObject.GetComponent<FirstPersonCameraScript>();
thirdPersonCamera = gameObject.GetComponent<ThirdPersonCameraScript>();
isFPSCameraActive = false;
fpsCamera.enabled = false;
isThirdPersonCameraActive = true;
thirdPersonCamera.enabled = true;
(The bools are used later in the code)
I figured this would work, seeing as the above code means that when I hit the play button, the fpsCamera is turned off and the thirdPersonCamera turned on. However, I'm still getting that same 2 audio listeners in the scene issue.
Am I overlooking something? Sorry for yet another question by me, I'm still learning. This is a huge important part of my game, so learning how to fix this would be VERY beneficial :)
An other way to do that could be to have only one camera, and change its position and eventually rotation when the user pushes the specific button. Otherwise I don't really know what to do if you really want to keep the 2 cameras...
That's what I was thinking I should do. Not that hard to do, probably. Thanks!
Actually it's very simple, and if you want a nice effect, you can also animate the movement :)
It avoids an abrupt change.
Answer by special821 · Mar 08, 2013 at 03:17 PM
Don't know if you've moved on from this, but seems to me you're only disabling the script. You should also disable the Audio Listener component so that only one of your cameras has it enabled. This way you can switch between the one you use.
bool isFPSCameraActive = false;
bool isThirdPersonCameraActive = true;
FirstPersonCameraScript fpsCamera;
ThirdPersonCameraScript thirdPersonCamera;
public AudioListener fpsListener; // Public so you can assign it in-editor
public AudioListener thirdPersonListener;
void Start () {
fpsCamera = gameObject.GetComponent<FirstPersonCameraScript>();
thirdPersonCamera = gameObject.GetComponent<ThirdPersonCameraScript>();
isFPSCameraActive = false;
fpsCamera.enabled = false;
fpsListener.enabled = false; // Deactivating the fps listener
isThirdPersonCameraActive = true;
thirdPersonCamera.enabled = true;
thirdPersonListener.enabled = true; // Activating the third person listener
Answer by MaGuSware™ · Dec 24, 2012 at 10:51 AM
Camera's come with an audio listener component on them. Just remove the component from one of the cameras.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Flip over an object (smooth transition) 3 Answers
Modifying lense shift relative to Vector3 position 0 Answers