"PlayOneShot()" not working properly in Unity 3.1

Hello,

when I call PlayOneShot() pretty often, sometimes it doesn't play the sound. The thing is that I recently updated from Unity 2.6 to Unity 3.1 and I don't remember experiencing the problem in the older Unity, whereas Unity 3.1 seems to have it.

Has anyone experienced a similar problem? Or maybe knows the cause or a solution?

To give you some more info, when I want to play a sound, I always call a function (with an audio clip and an audio source specified as parameters), which is in an external script. That function checks, whether the audio is on or off (the variable is set in the PlayerPrefs), and if it's on, it then calls the native Unity PlayOneShot() function. Although, I have no idea how this could mess things up.

Anyway, I would really appreciate it if you could help me somehow. Thanks in advance.

Figured out what may be your problem. If you are doing a 2D game, make sure that all your audio files have the 3D Sound checkbox turned off.

I am having the exact same problem. I have several different audio sources playing different sounds to try and remove the problem but it still arises. Have a look at my game here. Use the sequencer add lots of beats and bump the tempo up to 240bpm. Listen to the sound deteriorate. Same thing happens in the editor and on standalone executables. Anyone found a fix?

having the same problem on Unity 3.4

You might want to check the priority of your sounds. I haven’t played with it too much, but I know that depending on the priority’s of the sounds playing Unity will cut some sounds out if there are too many playing at once. It’s like when you have too many point lights in the scene, and depending on the quality level, Unity will stop rendering certain point lights to save on memory.

yup, just looked it up:

http://unity3d.com/support/documentation/ScriptReference/AudioSource-priority.html

using UnityEngine;
using System.Collections;

public class PortaoSaidaSomScript : MonoBehaviour {
public bool tocar;
public AudioClip PortaoAudio;
// Use this for initialization
void Start () {
tocar = false;
}

void Update () {
if (!tocar)
	{	
		 toca();
		tocar=true;
	}
}

void toca()
{
	audio.PlayOneShot(PortaoAudio);
}

}

Just dealt with same problem. Not sure what causes but I made the same observation. It is related to AudioSource.PlayClipAtPoint() once replaced with audio.PlayOneShot() everything seems to be fine.

I wrote a post about it if you want to check for more details and code examples.