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?

How many sounds are we talking about here? I believe there is a cap on the number of sounds an AudioListener can process.

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.

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.