In a previous post I was discussing how to use the Sound Mixer to handle different effects as the game transitions between game modes.
However, I wanted to experiment a bit with the possibility of using layered music for Exploration and Combat.
Disclaimer: I’m not a musician, I have a very primitive understanding of musical theory, enough to know I know nothing.
Imagine you have a musical composition that loops seamlessly. This composition has a base layer with some percussive elements and bass, enough to give it a clear root, on top of that you have two different options, a Combat layer that has stronger percussion and brass, harsh sounds with a martial feeling, and an alternative Exploration layer that shares the same melody, but with soft strings and woods. The Sound of Silence, by Disturbed and by Simon and Garfunkle, but with a shared drumbase.
Understanding MetaSound
To be fair, I don’t entirely understand MetaSound yet. Unreal MetaSound is a programmable audio system, that allows to process waves (let’s say audio files, although you can synthesize waves too) through a series of operators, like a pedal chain maybe? and route them to an audio output.
Unreal sees a MetaSoundSource as if it were a simple audio file, but inside there can be any number of rules in a processing pipeline.
I have used a few rules, for instance I have a rule for selecting random footstep sounds from a list. Each time a character’s foot hits the ground, it plays the MS_Step source, inside there’s an array of different audio clips, it selects one at random and plays it with a little pitch variation each time.
MetaSound and Layered Music
For this example I got my friend Jaifos to give me a track split in two layers. We’ll call these the Base layer and the Top layer.
Each music file is imported into UE5 and set to loop. Then I made a MetaSoundSource, with two wave assets (audio files) and assigned them to each of the music files. I also added an input of type float (a number between 0 and 1), which will control the volume of the Top Track.

Inputs are data values that can be modified through script. In this case I need a float input to modify the volume of the Top Track.
Variables are data values for internal use only, to modify the behaviour of the pipeline. In this case the two Wave Assets in which each of the music files is assigned.
Now I need to create the pipeline. I need both tracks to play at the same time, stay in sync, and mix their output, but I also need to control the volume of the Top Track, so that I can turn it on and off at will.

The OnPlay event ensures both tracks start at the same time, and stay synchronized. The output of the Top track is multiplied by the TopVolume input (0 to silence that layer, 1 to mix it in full). The result is then added to the Base track to achieve the final mix which is then routed to the final output, in this case a Mono channel.
Controlling the volume by code
Once the pipeline is ready, I have to manipulate the TopVolume input when a specific event happens. In this example the audio starts with only the Base Layer on, once I enter a designated area, the Top Layer fades in, and if I exit, the Top Layer fades out again.
To achieve this I made an Actor blueprint with an Audio Component. This component has my MetaSoundSource assigned and is set to “AutoActivate”

In the logic of this Blueprint I created two custom events, one to fade in and one to fade out.

From here I can just call each of the events whenever I want. In this example I set it to FadeIn once the character enters the WhiteBox in the map, and to FadeOut once the character exits.

The Result
I still haven’t figured out what’s wrong with my OBS. The audio sounds terrible, I hope you can notice the difference. Sorry Jaifos for butchering your music with my crappy video capture.
The Base Layer has Bass and Hi-hats, the Top Layer has keyboards. Notice how the keyboards only sound when the character enters the white area.
I still don’t know if we’ll do this for the game, but It’s nice to know we have this tool and it is so easy to use.
Thanks Jaifos!
Click the image to find my friend’s Sound Cloud page.

























