Space Shooter: Adaptive Music with Wwise and Unity

In this article I want to go over how to set up some adaptive music using Wwise with our Space Shooter project.

The way it will be set up will be determined by your specific needs. In this case I want the music to change with every wave of enemies. I have composed a short musical loop with 4 layers, or 4 tracks.

The first track is a simple pad. The next track is some spiccato strings. After that will come a synth line and when the boss battle comes a drum section enters. You can find the same audio files here:

https://drive.google.com/drive/folders/1Q1JvsmZVTFG1HAY6tYO3junTnuRZYW4I?usp=sharing

I’ll cover the cymbal roll file included in there as well.

Lets get into it!

In Wwise I want to switch over to the Interactive Music layout.

In the Interactive Music Hierarchy I want to create a Music Playlist Container. I’ll just call it “Music”. As a child of this playlist container I want to create a Music Segment. Then I want to create a new track for each one of the music files (Synth, Drums, Pad, and Strings).

I’ve imported the audio files into their respective tracks. Now I want to make sure the music loops. To do this, I have to click on the Music Playlist Container and drag the Music Segment into the Music Playlist Editor and set the Loop Count to infinite.

Checking back on the Music Segment, you can see each of the tracks. I want to basically turn each track off and on individually. To do this I will make each one of these tracks a Switch track by right clicking and selecting Switch.

Then I made a sub track for each track by right clicking and selectring create sub track. The sub track will be blank. This will represent the track being off.

The way I handle this is similar to how I handled the Powerups. I create a switch group for each track and then within the switch groups I have an On and Off switch. Then I assign each track its respective switch group and then set the default switch to off.

I have the Pad assigned to Wave1, the Strings assigned to Wave2, the Synth assigned to Wave3, and the drums assigned to BossFight. You can change yours up however you see fit.

Now I need to associate each track with its specific switch by right clicking the switch track and clicking “Set Association”. The track will be associated with on and the blank track with off.

After that is all set up I need to define transition behavbior (from off to on and on to off).

In each one of the tracks in the Music Segment there is a Transitions tab.

If you click on the Any to Any transition while in the Designer layout, you’ll see rules for setting up the exit source and fade times.

I have all of my tracks set to “Next Bar” and the fade out values are 3 and 3, and fade in is 3 and -3.

Now I simply create an event called “Music” from the Music Playlist Container.

In Unity, since I want to have the waves of enemies manipulate the switches for the music, I’ll put my music event reference in the SpawnManager Script. In order to have the music switches work I need to call AkSoundEngine.SetSwitch() in the code. In my StartSpawning() script I’ll call this method and feed it some parameters.

Since this method needs 2 strings, 1 for the Switch group name and another for the switch name, I have created an array for each.

So in my StartSpawing method I have this.

The index of the array will directly correspond to the wave number. Since my waves start at 1 and arrays start at 0, I have to say wave -1 inside the brackets.

Now I simply have to put the correct group names and switch names in the arrays in the inspector.

You may have noticed there is another event called “Stinger” in there as well. Stingers are basically transition sound effects. Every time the wave changes I have the stinger called. This provides me with a sound effect as well as an opportunity to musically transition from wave 1 to wave 2 and so on by adding a cymabl roll.

SETTING UP STINGERS:

In Wwise, under the Game Syncs tab, I have created a trigger called “Cymbal Swell

In the Interactive Music Hierarchy I have a folder called stingers and within that I have a Music Segment for the cymbal swell.

I forgot to mention that I have the entry and exit cues for the music tracks set accordingly. This tells wwise when to start the track over while leaving a tail for the loop to fade out during the next go around.

I have the entry and exit cues set to the peak of the cymbal swell audio file. This is what tells Wwise where the downbeat is. Since I want this to line up with the music Wwise has conveniently made this super easy.

Check out the Music Playlist Container and navigate to the Stingers tab.

Yours will be blank. Just assign the cymbal swell trigger and what segment to play and when! easy peezy.

To actually call this event in Unity I have an event created for a sound effect to play when the new wave begins called Wave Alert. You can see here that I have the play event for this sound as well as a trigger event. So when this event fires the trigger will happen at the same time on the next bar.

In the Spawn Manager script I simply make another event reference, call it stinger, and then post it when StartSpawning is called (since this is where the new waves start).

Once this is all set up play the game and experience the newly adaptive music! :)

Result Here:

https://youtu.be/2JMEGOhGxTM

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store