- Home /
Problem with many audio sources playing at the same time
Ok, so i have a gameobject called "Enemy" with a script that deals with the AI...
After I kill the enemy, it spits about 20-30 blood drops that when they hit the ground (wich they do in milliseconds appart), they spawn blood splatters with audio sources...
After this happens, i cant ear anything else... be it guns, doors, sound effects, etc... none of them is heard :C!
If i reset the game, its audible again... but then again, if i kill the enemy, this happens again...
I have checked scripts and they are all fine.... I know this has to do with the fact that MANY audio sources are playing almost at the same time....
What i dont know, is why :C!
Please help me :CCCC
I have never encountered this, but it sounds like an overload. $$anonymous$$aybe you have hit the limit (if there's any, in such frequency). If I were you, I'd simply use AudioSource.PlayClipAtPoint(dropSound, drops.transform.position). All you need is a Listener, which I assume your camera's already having.
Answer by Addyarb · Apr 28, 2015 at 10:05 PM
I have dealt with a very similar issue. Blood splatters happening too frequently when enemies get hit. Due to algorithms of most audio mixers, sounds will be turned down based on a percentage of their volume when a new sound enters the mixer. The best way to handle this is to ask a Sound Manager script to play the sound, and to start an IEnumerator (Coroutine) to check the last time the sound was played. For instance:
AudioHandler aHandler;
void Start(){
aHandler = GameObject.Find("Audio_Handler").GetComponent<AudioHandler>();
}
void PlaySound(Audioclip aClip){
aHandler.PlayAudio(aClip);
}
Audio Handler Script
bool canPlay;
void PlayAudio(Audioclip clip){
if(canPlay)
canPlay = false;
GetComponent<AudioSource>().PlayOneShot(clip);
StartCoroutine(Reset());
}
IEnumerator Reset(){
yield return new WaitForSeconds(.2f);
canPlay = true;
}
And i would attach the the Audio Handler Script on the audiosource that stops playing right :P?
I would create a new GameObject in your scene called "Audio_Handler" (in this case) and then attach the script to that. Then, whenever you need to play any sound at all, play it through the AudioHandler script so that only a certain amount of sounds can play in any given time. Of course, the Audio Handler will have to have an Audio Source attached to it, but it will be the only Audio Source in the game. This makes audio much easier to manage.
Ohhhh, sorry, sometimes i can really lack logic xD! Thank you veeeery much :D!
Don't be sorry, it's no problem at all :) Good luck with your game!
If this answer is helpful, please mark my answer as correct by clicking the button under the "Thumbs Down" button on my answer.
Thanks!
Wow! It actually is correct, i just found another person with the same problem and the answer was the same, we should create an handler and play all the sounds through it :D! Thank you very much ^_^!!!!
Thumbs up and correct answer for you, and good luck with yours as well ;)!
Your answer
![](https://koobas.hobune.stream/wayback/20220613194304im_/https://answers.unity.com/themes/thub/images/avi.jpg)