- Home /
Audio Not Always Playing
The way my audio is set up is that I have all of the sources as child empty gameobjects under the main object, and they are referenced to in script via something like this;
var HitSound1 : AudioSource;
HitSound1.audio.Play();
The problem I'm having, however, is that sometimes audio just won't play. Note that I have a lot of AudioSources going at the same time which may be a part of the problem, but everything is equal in priority so I don't understand why some aren't being heard. There's a mix of a few 3D ones and a whole ton of 2D ones if it matters, anyone got any clues?
Answer by aldonaletto · Jul 17, 2011 at 05:16 PM
I've just tested 32 3D sounds playing at the same time, and no one failed (in a PC Intel Core Duo 1.8 GHz). Unless you're developing for mobile devices, the max sounds limit isn't your current problem. I can suggest two possibilities:
1- Some sounds are not being Play'ed at all due to errors in the code. You can check this by adding the line I've suggested before - it would help to know if each sound is being played when it should:
...
HitSound1.audio.Play();
print(HitSound1.audio.clip.name);
...
2- Some of the audio sources are far enough from the listener to be heard. That's my favourite hypothesis, since our audition "prefers" to listen the louder sounds, and just ignore the weaker ones when there are several sounds playing at the same time. Another thing: if a continuos 3D sound is playing somewhere and you rotate the Listener slowly, you can notice that there are some "null directions" at which the sound becomes almost inaudible (it looks lika a kind of "phase cancelation"). Maybe the sounds you think are not playing are actually inaudible due to distance or direction.
Answer by testure · Jul 17, 2011 at 07:08 AM
How many sounds are we talking about here? I believe there is a cap on the number of sounds an AudioListener can process.
Well since each AudioSource is responsible for only 1 clip, I'd say about 20 are referenced, but only about 5-10 will be heard simultaneously due to the game's control scheme.
There's a limit, for sure! Each Audio Source requires a lot of calculation while playing, and all sounds currently playing are mixed at the Audio Listener. But I suspect the limit is well above 10 sounds. Add a print to the play code to know if it's working:
... HitSound1.audio.Play(); print(HitSound1.audio.clip.name);
What about having more than one listener? Would that help any?
Answer by TheEmeralDreamer · Sep 22, 2011 at 06:40 PM
Use Audio.PlayOneShot(yourclipname) This will allow you to play more than one clip at once if you do this for instance:
var clip1:AudioClip; var clip2:AudioClip;
function PlayDualAudio(firstClip:AudioClip,secondClip:AudiClip,volume:float)
{
Audio.PlayOneShot(firstClip,volume);
Audio.PlayOneShot(secondClip,volume);
}
Then simply call play audio and give it the arguments.
Your answer
Follow this Question
Related Questions
Sound getting deeper 2 Answers
How to stop an Audio Clip without an Audio Source? 1 Answer
Best way to play audio sound effects 1 Answer
Can't get my sound to work.. 1 Answer
3D Sound Max Distance Not Working. 0 Answers