- Home /
"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.
Are you calling PlayOneShot() on an audio source that's already playing another sound?
Yes, the audio source is playing several sounds at a time. Is there a limit of how many sounds can be played at once or something?
I'm having the same problem, seems like a bug since I didn't have this issue in earlier versions of Unity. Some of my sounds won't even play at all.
Having the same issue. Has it been fixed? Will try updating to latest version, to see if it makes a difference. (havent updated for months)
Answer by JGeorge · Jan 11, 2011 at 03:34 PM
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.
Well, those checkboxes are turned off, actually.. Although the audios are stereo. $$anonymous$$aybe I should force them to mono or something? However, I don't really get why that should help.
Answer by Will 7 · Feb 04, 2011 at 05:12 PM
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?
Answer by zzzzz4512 · Jun 06, 2012 at 12:34 PM
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
Answer by godoy · Nov 15, 2012 at 11:48 PM
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); } }