Making Music With Unity

I learned many things from being broke back in high school. After quitting my job to focus on web game development I discovered Goodwill threads, learned exactly how far you can drive with one gallon of gas, and developed the ability to squeeze 5 quarters from a dollar.

My name is Nelson Scott and I’m Sharp Notions’ perpetual game design intern. I got my start in games by creating and releasing passion projects. Without a dime to spare, I had to learn to do things by myself, which gave me a unique perspective on the overall process of game development.

The word “problem” is a common mispronunciation of the word “challenge”. Trust me, you can believe everything you read on the internet. My early challenges in game development came from learning to do things I couldn’t pay someone else to do for me. This included creating my own art assets, generating my own sound effects, and recording original music for my games. I enjoyed recording music so much that I convinced my boss to let me provide the music for our own games at Sharp Notions.

We use Unity for our game engine, and in this blog post I’ll go over some of the details on how I used it to create music for our games. I’ll detail some of my processes on Donut Slinger, PictoBlanks, and Navi – an in-development VR game that we’re currently producing with a group of students from RIT.

Learning Digital Audio Processes

Craft Brewed Games

The music for Donut Slinger was the most difficult audio project I’d worked on to this point. Prior to this, I had only worked with live instruments and had no experience programming compositions on a computer. To record the tracks for this game, I had to learn a DAW (digital audio workstation) called Cubase.

The learning and recording process took a week or two. I would compose when I had downtime at college; while at the dining hall or doing laundry. Later, I could write MIDI compositions within Cubase and test them against its library of virtual instruments until I settled on the right sound. Once I was finished with a track, I would import the instrumental files into Adobe Audition to add final effects. I avoided adding reverb or delay effects in Audition to ensure that each track looped seamlessly within the game. If I needed to record a live instrument like guitar, I would do that in Audition using a connected Zoom H2 microphone.

The actual tracks are loops that are usually less than a minute long. Each city in Donut Slinger has its own theme music, and variations for special events like boss battles. I chose more traditional instruments like drums, bass, and piano since the game was intended to be comfortable, inviting, and filled with familiar tasty treats.

Writing our own Sound Manager

Playing the tracks within Unity was a simple process. We wrote a “sound manager” which handled playing sound files and looping them as needed. The sound manager was a singleton attached to a GameObject in the main scene so that sounds could be triggered from anywhere in code. Any 3D sounds that were needed were played from spawned prefabs inside the game world, but most sounds were played from the main scene’s canvas because they only required 2D playback. Unity handled audio compression for us while exporting the game, so our sound files didn’t increase the app’s size by much.

A few months prior to my audio work, Unity 5 was released with a handful of new features including an all-new audio mixer. Another feature called “snapshots” allows Unity developers to swap settings on audio channels using scripts. I was able to use this feature to apply a higher pitch and reverb when the player gets the Sugar Rush powerup. Since I applied the reverb effect through Unity, it didn’t cause any problems with the continuity of the audio loops. This never made it into the final game, but fun experiments like this have helped me develop my Unity audio skills.

Composing elevator music

Craft Brewed Games

Everyone and their grandmother can play our newest game, PictoBlanks, since there are no challenge levels or boss battles to be found. It’s a leisurely game about creativity where players take turns translating sentences back and forth between emojis and words. Unlike Donut Slinger, PictoBlanks isn’t split into different sections that require their own music loops, so less work was required on my end.

Most mobile gamers play their games with the sound off. Players will not turn up their phone volume without a good reason. I would love to hold our game hostage until the player opts to sample my tasty rhythms, but I know that’s the fastest way to get our app removed from their phones. The best I can do is offer the most tolerable style around for those brave enough to blast their phone volume on the subway: elevator music.

When I’ve played the music for friends and coworkers, that’s the most common feedback I’ve received: it sounds like it can be played in an elevator. I don’t know how much cash runs through the elevator industry but if you need a sharp solution… you know who to call.

PictoBlanks only needed one looping track. I discovered the main melody while playing my guitar one night and composed the rest over time by working in Cubase. I took a risk and included a whistle instrument, which actually turned out to be the most notable part of the track. In my opinion, the catchiest aspects of a song often come from instruments that sound weird during the first listen.

Implementing my whistle-laden track was painless thanks to the knowledge I had gained while working on Donut Slinger. Once again, we used a sound manager singleton and played 2D effects from the scene’s canvas. Since PictoBlanks is a game consisting entirely of UI, button click events were assigned through the inspector to play sound effects. Playing effects through code was only required for special tasks – like the whistle track dance remix easter egg…

Developing procedural audio

Navi is an in-development mobile VR game in which players must work together to escape a hedge maze. Craft Brewed Games (the Sharp Notions game development studio) is currently working with a group of RIT students to release this project. In addition to general development, my job on the team is to cover all music and sound.

Players use visual and audio cues to navigate the maze. They must be in constant communication if they want to escape before time runs out. To help guide the players I am composing small loops for different scenarios. These loops are varied but share the same musical key. My goal is to create a guided, slightly random music track that takes some time to feel stale.

On this project, I wanted to use this opportunity to explore a different way of creating music. I still compose my loops inside of Cubase, but instead of mixing a finished track in Audition, I export the individual instrumentals into Unity. My system starts with the basic sound manager and adds a Unity audio source for each instrument. The audio sources are then told to play in sync from the logic that I write.

Essentially, I am conducting the composition through code. I’m able to create a cohesive sound by assigning the loops to the different instruments I create. The loops are categorized based on which scenario they should be played in and won’t be played with loops that don’t match up. To add variety, I sometimes bend the timing or pitch of certain audio sources.

I used Unity’s audio mixer snapshot feature to apply effects to the instruments and audio channels. This allows the tracks to loop seamlessly without interruption from various post-processing effects. The overall composition has a dreamlike feel due to the reverb effects I’m able to apply within Unity.

The results have made me happy so far. The music is randomly generated, but it doesn’t sound like a mess. As time goes on, I will be able to add more loops to expand the piece even further. Unity’s features provided me exactly what I needed to make this happen without any compromises.

Unity is an excellent engine for independent game development and its features for sound production offer a lot of options for anyone looking to do cool things with their audio.

PictoBlanks is now out on both iPhone and Android. Download it below to hear some of that sweet elevator music.