Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by chaguaramo · Nov 07, 2013 at 11:16 PM · audio clippingaudio priority

How to change priority of audio clips

Hi,

im creating a scene with 128 recorded ambient sounds. Each audio source for a different position in the scene. But I´m exceeding the play limit of 32 simultaneous audio files. It does´n work to use the collide function for play the sounds because the ambient sounds must be played simultaneously to stay synchronized. Can I write a script to change the priority of each audio clip while collide to each game object?

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by aldonaletto · Nov 08, 2013 at 12:36 AM

If these sounds are 3D, I suspect that you don't have to worry about this: according to the docs, sounds that are less audible (the farthest ones) are occluded first when there are more AudioSources than available mixer inputs (priority is also taken into account).

Anyway, I suppose that you could use a trigger to raise/lower the priority of each sound source: add or child a sphere trigger of the desired radius (range) to the player, and add also a kinematic rigidbody to it (moving triggers require a rigidbody, even kinematic), then place this code in every AudioSource:

 function OnTriggerEnter(other: Collider){
   // audio source inside player range:
   audio.priority = 100; // set a higher priority
 }
 
 function OnTriggerExit(other: Collider){
   // audio source out of player range:
   audio.priority = 128; // restore default priority
 }

NOTE: Every object having one of these AudioSources must also have a collider in order to be detected by the trigger (rigidbody not required).

Comment
Add comment · Show 2 · 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 chaguaramo · Nov 08, 2013 at 02:32 PM 0
Share

Thank you, it was exactly what I was looking for. But it still not working. I find out that there are only 100 sound sources playing at the same time and in the scene are 160 sound sources.

When I actived "play on awake" for all the audio sources, some random sources stay inactive. If I only activate "play on awake" to a reduced amount of audio sources the selected sources play with out problems but the rest (unselected sources) don´t can be heard. Is it possible to change the "play on awake" function after the game is started?

avatar image meat5000 ♦ · Nov 08, 2013 at 02:36 PM 0
Share

You'll only have so many sound channels available. The idea of priority is to ensure that the sounds you want to be heard are heard at the expense of the low priority sounds not being played.

avatar image
0

Answer by chaguaramo · Apr 04, 2014 at 01:52 AM

Hi, with this script I can create audio zones with a random form that are on while the rest of my audio sources are turned off. So I could reduced the numbers of audio sources playing simultaneously. Thanks to Daniel Murcia!

For use it, create a surface with the form you need and place it on the floor level, add a mesh collider, select-on the is trigger option, unselect the mesh render option and attach to the surface you have created the audio sources you want to be played simultaneously when enter in the zone designed by your surface.

So you can differentiate audio zones that are played at once when they are triggered.

 #pragma strict
  
 var audioSources;
  
 function Start(){
     audioSources = gameObject.GetComponentsInChildren(AudioSource);
 }
 function OnTriggerExit(){
     Debug.Log("stopping sounds");
     Debug.Log(this);
     var self = this;
     for (var source:AudioSource in audioSources) {
         Debug.Log(source);
         source.Stop();
     }
 }
  
 function OnTriggerEnter(){
     Debug.Log("starting sounds");
     Debug.Log(this);
     var self = this;
     for (var source:AudioSource in audioSources) {
         Debug.Log(source);
         source.Play();
     }
 }
Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

17 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

Related Questions

Audio Sounds Blurring Together 0 Answers

Record in game Audio on android 2 Answers

Play audio clip on more than one object from another gameobject 2 Answers

Dynamic Sound: Wind up Wind down Audio 1 Answer

Help adjusting Audio script settings to a specific sound 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