AudioSource.ignoreListenerVolume ineffective?

Hi, I have a project with a music track running in the background. The audiosource for the music has the ignoreListenerVolume set to true. I have a button in my scene that, when pressed, will switch the AudioListener volume between 1 and 0, but when this happens the AudioSource that should be ignoring the change does not, and is silenced with all the other sounds.

However, changing the volume of the source (which remains at 1) with the editor gizmo slider when the listener’s volume is at zero re-enables the sound. From this point on, when the button is pushed, the rest of the audio will go silent and the source that should ignore the listener does so.

Unfortunately, this fix cannot be recreated in code, as manually changing the source volume in code has no effect on it, even though the volume variable can be seen to change on the editor gizmo. Only by using the gizmo slider can I seem to get the ignore variable to actually have any effect.

Has anyone successfully used this variable with recent builds, and if so could you please share the implementation? Or else, can anyone explain why the editor gizmo may fix the problem, but doing the same thing through code does not?

Thanks :slight_smile:

Hi!

Apply this script to a gameObject with your AudioSource component:

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(AudioSource))]
public class MusicController : MonoBehaviour {
    void Awake() {
        AudioSource audioSrc = GetComponent<AudioSource>();
        audioSrc.ignoreListenerVolume = true;
        audioSrc.Play();
    }
}

If ‘Play On Awake’ is checked on your AudioSource component, then AudioSource start to play sound without ignoreListenerVolume setted to true. (Even if it is set in Awake() method, like in my script). Always start Play() music only after setting ignoreListenerVolume to true.

Hope this helps.