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 :slight_smile:

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

Camera’s come with an audio listener component on them. Just remove the component from one of the cameras.