In Unity 4.2 the AudioSource.PlayOneTime is ignoring AudioListener.volume

Create a game object, add a AudioSource, set both clips.

If you click toggle, play, play one, The “Play One” will play in Unity3d 4.2

#pragma strict

var clip: AudioClip;

function OnGUI() {
	if (GUI.Button(Rect(0,0, 100, 100), "Toggle")) {
		if (AudioListener.volume == 0) AudioListener.volume = 1;
		else AudioListener.volume = 0;
		Debug.Log("Toggled to "+AudioListener.volume);
	} 
	if (GUI.Button(Rect(100,0, 100, 100), "Play")) {
		Debug.Log("Play");
		audio.Play();
	} 
	if (GUI.Button(Rect(200,0, 100, 100), "Play One")) {
		Debug.Log("Play One");
		audio.PlayOneShot(clip, 1.0);
	} 
}

Exactly the same problem.
I use AudioListener.volume to control the game’s SFX volume. It works in Unity 4.1, but not in 4.2!

Also, AudioSource.ignoreListenerPause doesn’t work. When you set AudioListner.pause to true, audio sources with “ignoreListenerPause = true” will also be paused.

Seems both the pause and volume property of AudioListner is broken in Unity 4.2.:-?

I got same problem too.
The volume of AudioSource.PlayOneShot does not effect by AudioListener.volume.

And I’ve made a repro project to Bug Reporter. Case No. 553706

Hi,

Does anyone know how to control the Master Sound Volume without using AudioListener.volume ?

The Unity QA team has reply me that they could reproduce this bug. But I just don’t know when to get the new release to fixed this issue.

If you have a central audio management you can simply control the volume by yourself (It was my case). If not, I think better simple to rollback to least unity3d working version.

And stay there until unity relases 4.3, so you can have sure that 4.2 become stable :stuck_out_tongue:

I’ve run into this issue as well. Hopefully it’s fixed in 4.2.1 which is supposed to be released very soon!

I’ve tried the 4.2.1 release.
This bug is still there :frowning:

Shame :frowning:

Can confirm this is still in 4.2.1. Current workaround I’m using is just passing AudioListener.volume into the second parameter of PlayOneShot, as the value is right, it’s just not being applied properly behind the scenes I guess

audio.PlayOneShot(clip, AudioListener.volume);

Thanks in advance for your advice :smile:

Update:
Unity QA team give me a reply in FogBugz:

:stuck_out_tongue:

Yep I get the same thing. Thanks for the workaround wallis2xk!

Also if there is a Unity guy watching this thread there is another issue with the audio introduced in Unity 4.2

The AudioListener.pause setting returns to false after the game regains focus when set to true before losing focus. To work around this I had to set the AudioListener.volume to 0 and in the first Update() after OnApplicationFocus( bool focus ) is called I return the volume to what it was and restore the pause state as well. It’s a bad hack but the only workaround I could think of for the time being.

Note: I had to set the volume = 0 in this hack because otherwise you get a split second of audio playback when your game regains focus. I also had to reset the pause state in the Update() function because it gets set to false after the OnApplicationFocus event so you cannot restore it there. :confused:

I can confirm this issue is still present in Unity 4.2.2. Your workaround should fix the problem.

This is now fixed in 4.3