• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by ticofa · Apr 28, 2015 at 09:41 PM · audiobugaudiosourcestopmany

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

Comment

People who like this

0 Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Pharaoh_ · Apr 28, 2015 at 09:53 PM 0
Share

I have never encountered this, but it sounds like an overload. Maybe 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.

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

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

Comment
ticofa
Westland
elpair

People who like this

3 Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ticofa · Apr 28, 2015 at 10:12 PM 0
Share

And i would attach the the Audio Handler Script on the audiosource that stops playing right :P?

avatar image Addyarb · Apr 28, 2015 at 10:15 PM 0
Share

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.

avatar image ticofa · Apr 28, 2015 at 10:18 PM 0
Share

Ohhhh, sorry, sometimes i can really lack logic xD! Thank you veeeery much :D!

avatar image Addyarb · Apr 28, 2015 at 10:22 PM 0
Share

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!

avatar image ticofa · Apr 28, 2015 at 11:02 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Several audiosources play at the same time 1 Answer

Audiosource weird bug Help please 1 Answer

AudioSource.PlayOneShot only works ONCE on Unity 5? 1 Answer

Pause Menu Audio 1 Answer

Collider isTrigger for audio clip lets me pass through object. How to fix? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges