- Home /
How do you find 2 audio listeners in scene?
I googled this and checked the forems and did not find a answer so I'm asking.
I Keep getting this error: "There are 2 audio listeners in the scene. Please ensure there is always exactly one audio listener in the scene."
Is there a way to find this out instead of looking at every single game object? I am using playmaker so there may be appoint at which 2 cameras are active for a brief time. So I was wondering if there was some error log telling you the 2 game objects? if not, would be a nice addition to add to unity 5.1
Also, is there a way to force whatever audio listener as the only one to work? A sort of solo button? If not, having a command to turn off all audio listeners except 1 would be neat for unity 5.1
Answer by KickBack · Mar 19, 2015 at 12:36 AM
In the hierarchy at the top right there is a search box. Click on the magnifying glass icon and switch to "Type". Then type "audiolistener" in the text field. That should return all the gameobjects that have an audio listener.
Edit: Also, as far as I know, there is no way to force only one audio listener to work.
Thanks for the reply, but I know which ones have audio listeners on them. It's the objects with cameras. What I was asking is how do you know which 2 are active at the same time to give the error warning in the console.
Thanks, you can also select type = All, and then your search bar will look also for components of obj's
Answer by paulygons · Sep 23, 2015 at 10:27 PM
@wheretheidivides I'm having a similar problem. I built code that tries to detect that two audio listeners are active then shuts down one of them. It seems to work in some cases.
//turn off AudioListener component if one already exists in the scene
//WARNING! This finds disabled listener components!! (although not inactive GOs with listeners on them)
AudioListener[] myListeners = FindObjectsOfType(typeof(AudioListener)) as AudioListener[];
int totalListeners = 0;//find out how many listeners are actually active
foreach(AudioListener thisListener in myListeners){
if(thisListener.enabled){totalListeners ++;}
}
if (totalListeners > 1){
//turn off my audioListener component
AudioListener al = GetComponent<AudioListener>();
al.enabled = false;
}else{
//turn on my audioListener component
AudioListener al = GetComponent<AudioListener>();
al.enabled = true;
//print ("turn on audio "+name);
}
Your answer
Follow this Question
Related Questions
GetSpectrumData differance between pc and android 1 Answer
Storing many array values in a variable 1 Answer
Visualize audio spectrum with delay 0 Answers
How to play multiple sounds simultaneously 2 Answers
Optimised audio system design for mobile 0 Answers