How to play a sound effect from a collision

This continues from where we left off with How to create your first Sound Effect with Variations. Make sure you've done those steps first.

     
  1. Playing sounds from collisions or triggers 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.
  2.  
  3. Create or locate a game object in your Scene that you'd like to play a collision sound effect when it collides with something. It must have a Collider component of some sort. Take a look to see if this or the object has "Is Trigger" checked because it will matter in the next couple steps.
     
  4.  
  5. Add the Event Sounds component to the game object from the menu: Component -> Dark Tonic -> Master Audio -> Event Sounds
     
  6.  
  7. Select "Collision Enter" from the Event To Activate dropdown (this will not be in the list unless you check the "3D Physics" checkbox on the Welcome Window, so do that first if you haven't already. This will add a section for the Collision Enter event so you can specify some audio behavior to occur when that event happens. There are dozens of other events to choose from as well.

    Note: you will use "Trigger Enter" instead if your collider has "Is Trigger" checked. If you're not using 3D, there are equivalent events starting with "2D" as well.
     
  8.  
  9. You have the correct Action Type selected: Play Sound. So go ahead and choose the Sound Group you want to play from the Sound Group dropdown.
  10.  
  11. The Sound Group will now play (a random Variation) when the Collision Enter event happens. You can optionally use the Layer / Tag filter sections to only play the sound if colliding with a certain layer and/or tag, which is usually what you want.
  12.  
  13. If you want to add more audio behavior, click the Add button in the Action title bar. You can have any number of Actions and they will occur top to bottom. Go ahead and hit the play button once you have a collision ready to happen to hear the Sound Group.
 
Continue with the next Quick Start, How to create your first music playlist!