x


"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.

more ▼

asked Nov 27 '10 at 09:40 PM

DominoOne gravatar image

DominoOne
38 2 2 5

Are you calling PlayOneShot() on an audio source that's already playing another sound?

Nov 27 '10 at 10:19 PM Jesse Anders

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?

Nov 30 '10 at 12:38 PM DominoOne

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.

Jan 02 '11 at 07:35 AM XRA

Having the same issue.

Jan 11 '11 at 02:59 PM JGeorge

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)

Feb 09 '11 at 05:32 PM Carlsen
(comments are locked)
10|3000 characters needed characters left

6 answers: sort voted first

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.

more ▼

answered Feb 08 at 02:36 PM

IEvaluation gravatar image

IEvaluation
1 1

(comments are locked)
10|3000 characters needed characters left

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); } }

more ▼

answered Nov 15 '12 at 11:48 PM

godoy gravatar image

godoy
-14 1

(comments are locked)
10|3000 characters needed characters left

having the same problem on Unity 3.4

more ▼

answered Sep 30 '11 at 01:44 PM

Mloren gravatar image

Mloren
31 5 8 9

(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jan 11 '11 at 03:34 PM

JGeorge gravatar image

JGeorge
263 1 3 12

Well, those checkboxes are turned off, actually.. Although the audios are stereo. Maybe I should force them to mono or something? However, I don't really get why that should help.

Jan 12 '11 at 09:40 AM DominoOne
(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Jun 06 '12 at 12:34 PM

zzzzz4512 gravatar image

zzzzz4512
0

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1030
x525
x28

asked: Nov 27 '10 at 09:40 PM

Seen: 2970 times

Last Updated: Feb 08 at 02:36 PM