Ambient Sound

Note: This feature requires Physics3d to be installed in your project. Also, use the Welcome Window to enable Physics3d support in Master Audio if you haven't yet.

 
The Ambient Sound script is the best way to play ambient sounds, and that's not limited to stationary objects. If an enemy or an NPC should always be making a particular sound, use this script. The advantage of using it instead of Event Sounds' Start or Enabled event is that not all ambient sounds will be playing all the time. Only ones that are within hearing range of the Audio Listener will be playing at any time. That means that you will probably not have to resort to using Master Audio's auto-prioritization feature (in Advanced Settings) and will much have better performance with less audio playing. In a game with more than a few ambient sounds, this is invaluable.

It accomplishes this by creating a trigger the size of the Audio Source's Max Distance that follows the caller's position. There's another trigger that follows the Audio Listener (also containing a non-gravity Rigidbody - necessary for the trigger to work) and whenever the 2 triggers hit each other, the sound plays. Whenever the 2 triggers leave each other, the sound stops. Coupled with the Occlusion feature, you can get very efficient and dynamic audio even with hundreds of ambient sounds spread throughout a large Scene.
 
To troubleshoot any problems with Ambient Sounds, refer to the Troubleshooting page here.
 
 
 
The settings for the Ambient Sound script are as follows:
     
  1. Ambient Sound Group: Here you choose the Sound Group that will play when the caller is within hearing range of the Audio Listener. Note that once you have selected a Sound Group, you will see a mesh sphere gizmo in Scene View showing you the Max Distance of the Audio Source of the selected Sound Group.
  2.  
  3. Variation Mode: Choose either Play Random or Play Specific. If you choose the latter, you get a textbox where you can enter the name of the Variation you want to play.
  4.  
  5. Use Closest Collider Position: Check this box if you want to let the Audio Source always be positioned at the closest part of the collider(s). If this is checked, the Follow Caller option is disabled. Note that if you're using 2D colliders, it's the closest point on the collider bounds instead of the collider (which is square shaped). More settings appear once you check this box so you can specify which collider(s) to use:
       
    • Use Top Collider: Check this box to use the Collider on the same Game Object.
    •  
    • Use Child G.O. Colliders: Check this box to use the Colliders on all child nodes of this Game Object (only 1st level children).
     
    Note: This setting can cause performance losses with large quantities of Ambient Sound scripts, so you can control the maximum number of Collider Position Recalcs that happen in a single frame on the Ambient Sound Settings section of Advanced Settings. It defaults to 4 per frame max.
  6.  
  7. Follow Caller: Check this box if the caller will ever move, so that the sound will follow it also. If it's a stationary object, no need to check this, and you get slightly better performance.
  8.  
  9. Runtime Follower: At runtime, this show up and you can click it to find the "follower" Game Object that contains the trigger used by Ambient Sound.
  10.  
  11. Trigger Exit Behavior: This controls what happens when the Audio Source goes out of audible range. Normally, a fade is not needed unless you teleported over a large distance in a 3d game, or are using 2D sounds. Select Stop Sound (the default) or Fade Sound. If you choose the latter, you can specify the Fade Time in a field that appears beneath.
  12.  
  13. Min / Max Distance: This control appears if you have a Sound Group selected and lets you change the Min & Max Distance of its Audio Sources. The mesh sphere gizmo in Scene view can be seen changing size as you tweak. Normally, if your distance from the Audio Listener to the Audio Source is between zero and the Min Distance, the sound will be heard at full volume, and it starts to get quieter as you approach the Max Distance.