Performance: Audio Listener
Audio Listener affects how audio is processed and rendered in the game, impacting CPU usage and audio latency.
Jump into concepts and practice - no test required
GameObject mainCamera = new GameObject("MainCamera");
mainCamera.AddComponent<AudioListener>();
// Ensure all other cameras do NOT have AudioListener components activeGameObject camera1 = new GameObject("Camera1"); camera1.AddComponent<AudioListener>(); GameObject camera2 = new GameObject("Camera2"); camera2.AddComponent<AudioListener>();
| Pattern | Audio Processing Load | CPU Usage | Audio Latency | Verdict |
|---|---|---|---|---|
| Multiple Audio Listeners | High (duplicate processing) | High | Increased latency and glitches | [X] Bad |
| Single Audio Listener | Low (single processing) | Low | Minimal latency | [OK] Good |
AudioListener component in Unity?gameObject.AddComponent<ComponentType>(). The main camera is accessed by Camera.main.Camera.main.AddComponent<AudioListener>();. Other options misuse method calls or order.void Start() {
AudioListener listener = Camera.main.GetComponent<AudioListener>();
if(listener != null) {
listener.enabled = false;
}
Debug.Log(listener.enabled);
}
What will be printed in the console?enabled = false.listener.enabled is false, so Debug.Log(false) prints "False".