While playing your game, you might notice that the sounds are a little out of whack. For example, the music is a bit too loud, the death sounds are a tad too soft and the bullets are lacking pizzazz!
You could tweak each sound individually, but you have better things to do, such as killing aliens and designing an epic game.
Think about it; you’d have to play the game and keep track of the individual sound levels then make adjustments. While you could copy some of the changes, most of the work would be done by hand.
Before Unity 5, the painful one-at-a-time process would have been your only option, but now, Unity puts an audio mixer in your hands.
Note: This tutorial is part of a collection that teaches Unity development from the ground up. You can read the entire series over here. This series is free and does not require any account creation. All assets are provided. If you find it useful, feel free to buy me a coffee.
Creating an audio mixer
Go to the Project browser and select the Sounds folder. Click the Create button and select Audio Mixer in the drop-down. Name it MasterMix.

Click Window ▸ Audio ▸ Audio Mixer and drag the view to a place in the UI where it can expand horizontally instead of vertically.

In the Mixer, you’ll see only one group named Master. This group will affect anything that’s assigned to the Mixer. Right now, you have assigned nothing, so the Mixer is sitting idle.
Expand MasterMix in the Project browser, and you’ll see the group Master. Select SoundManager, and in the Inspector, find the audio source that controls the background music. Drag the Master group into the Output property.

Play the game again.

You’ll see a cool bar chart showing the sound levels of the Master group.
Editing in play mode
By default, you can’t adjust the levels while your game is being played — but you can when you click the Edit in Playmode button, so do that now. The Edit in Playmode button will appear when you play your game.

It’ll turn red and allow you to adjust levels while you’re in Play mode. Lower the volume to -20 and stop the game. You’ll notice that the group stays at that level.

Creating groups
The mixer’s capabilities shine when you create subgroups. Stop the game. Click the + in the groups section and name it Music.

In the Hierarchy, select the SoundManager, and in the Inspector, drag the Music group from the MasterMix to the background music AudioSource’s Output field (overwriting the existing Master setting).

Play your game again. You’ll see two levels in the mixer.

The Master group now controls overall volume, whereas the Music group controls background music.
In the Audio Mixer window, select the Master group and click the plus sign again. Call this new group Sound Effects. Under this new group, create the following groups: Gun and SoundManager.

Assign the SoundManager group to the non-background music AudioSource’s SoundManger output properties. For the Gun
group, select BobbleMarine-Body in the Hierarchy, and in the Inspector, set the Audio Source’s Output property to the Gun mixer group. When you play the game, you’ll see all the levels in action.

At this point, you could adjust the volume of each of the types of audio easily and independently.
Isolating sounds
Sometimes, you want to only listen to certain sound effects while you’re testing your game. For example, imagine you want to isolate the sound of the gun shooting so you can tweak that effect.
You could lower the volume for each, but that’s a bad idea because it’s easy to forget the original settings.
Notice that each group has three buttons on it. S is for Solo and it lets you isolate a certain group. M is for Mute and it works how you’d expect. B is for Bypass and it lets you bypass the effects in the group.
In the Music group, click the M button to mute the background music.

Play your game if you aren’t already, and you’ll notice that the background music is now muted; however, you can still hear the other sounds.
To fix this, in the Music group click the M button again to unmute the background, and then in the Gun group, click the S button to hear the gunfire — and only the gunfire.

Ah, sweet beautiful gunfire — music to a space marine’s ears!
Adding audio effects
Another cool thing the Sound Manager can do is add special effects to audio files. Click the Gun group to see the effect properties in the Inspector. Click the Add Effect button at the bottom.

Then choose Chorus. Set the Depth to 0.93
and fire that gun.

The chorus makes it sounds like rapid fire. Feel free to play around with more effects — the mixer comes with plenty of them. To hear the group without effects, click the B button.

Click B again to put the effects back. Click the S button to re-enable the rest of the sounds.
At this point, hopefully you see that the using the Audio Mixer is much better than trying to adjust sounds manually through the Sound Manager. If you’d gone that route, you’d lose the ability to easily set levels on individual sounds, group sounds, add effects and more. By creating a small subset of sounds, you can leverage the mixer while also enjoying the convenience of a single source. Set the final values as follows:
- Music to
-9
- Sound Effects to
0
- SoundManager to
-3
- Gun to
-8

So far, you’ve only scratched the surface of the possibilities with the audio mixer. You can also do things like hiding groups and saving them as views to aid your focus during various editing tasks. It’s also possible to take Snapshots to save different groups of settings — either for the sake of comparison or just for different situations.
Where to go from here
Wow! You’ve got sound now. You can download the completed code here:
https://drive.google.com/file/d/1z5IG5fpkrfN_g9R4i-2xw56oAvk0YVlY/view?usp=drive_link
With the addition of a few lines of code, your game should feel much more awesome. In doing so, you’ve learned:
- The basics of Unity sound, such as the difference between audio listeners and audio sources.
- The import settings for new audio files and how they can affect performance.
- How to call your sounds in code.
- How to balance all your sounds with the mixer.
- Bonus: How to create a power-up, complete with sound effects!
What’s left to do? You’ve got aliens. You’ve got lots of bullets. Sounds like you’re all set!
What you’re missing is an ending. In the next and final chapter for Bobblehead Wars, you’ll put the finishing touches on the game, e.g., lots of exploding aliens and a marine who can’t keep his head on straight. Lastly, you’ll provide a winning condition. You get started on Unity events in the next tutorial.
Discover more from Jezner Blog
Subscribe to get the latest posts sent to your email.