Unreal Engine 4 Audio Tutorial

In this Unreal Engine 4 audio tutorial, you will learn how to play audio in 3D space using different methods, and control audio volumes through a UI. By Tommy Tran.

4.7 (20) · 1 Review

Save for later
Share
You are currently viewing page 3 of 4 of this article. Click here to view the first page.

Setting Up Attenuation

Go to the Components panel and select RainAudio. Go to the Details panel and go to the Attenuation section. Enable the Override Attenuation setting.

The attenuation settings replicate how a sound loses its volume over distance. Under the Attenuation Overrides area, there are two settings you will use:

  • Radius: The maximum distance the player can be before the volume begins to fade
  • Falloff Distance: The distance the player needs to be before the sound becomes silent. This distance is in addition to the radius.

Take a look at the example below:

Unreal Engine 4 Audio Tutorial

When the player is within the inner circle (defined by Radius), the volume is at 100%. As the player moves from the inner circle to the edge of the outer circle (defined by Falloff Distance), the volume fades to 0%.

For this tutorial, set Radius to 300 and Falloff Distance to 400.

Unreal Engine 4 Audio Tutorial

This means the sound’s volume will be 100% when the player is less than 300 units away from the sound. As the player’s distance approaches 700 (300 + 400) units, the volume will fade to 0%.

If the player hasn’t moved out of the attenuation range when the cloud disappears, the sound will cut out. To fix this, you can fade out the sound.

Fading Out a Sound

Switch to the Event Graph and locate the FadeOut event. You can do this by going to the My Blueprint panel and going to the Graphs section. Double-click on FadeOut listed under EventGraph.

Add the highlighted nodes to the end of the node chain:

Unreal Engine 4 Audio Tutorial

FadeOut executes when a player touches the cloud. The Timeline (FadeTimeline) node outputs a value (Alpha) that goes from 1 to 0 over a specified duration. By using this value, the volume of RainAudio will fade.

Note: You can double-click on a Timeline node to open it and see how it works. If you’d like to learn more about Timelines, check out the official documentation.

There’s one setting you need to change in S_Rain before you can hear it in action. When a sound’s volume is 0%, it will stop playing. Since you are beyond listening range when the audio starts, the volume of S_Rain will be 0%. When you move into listening range, you won’t hear anything.

Unreal Engine 4 Audio Tutorial

You can fix this by using the Virtualize when Silent setting. This setting will always play the sound, regardless of its volume.

Click Compile and then close BP_Cloud. Navigate to the Audio folder and open S_Rain. Go to the Sound section and enable Virtualize when Silent.

Unreal Engine 4 Audio Tutorial

Now, S_Rain will play even if it is silent. Close S_Rain and then go back to the main editor. Press Play and then move into range of the rain clouds to hear the rain sound.

Unreal Engine 4 Audio Tutorial

In the final section, you will control the volume of the sounds using Sound Classes and Sound Mixes.

Sound Classes and Sound Mixes

A Sound Class is an easy way to group multiple sounds. For example, you can group all the music in one class and sound effects into another.

Unreal Engine 4 Audio Tutorial

To adjust properties of a Sound Class (volume, pitch etc.) during gameplay, you need to use a Sound Mix. A Sound Mix is basically a table and each entry in the table is a Sound Class. Each entry contains the adjustments the Sound Class should have.

Here is an example of what a Sound Mix could contain:

Unreal Engine 4 Audio Tutorial

By using the Sound Mix above, every sound in the Music class would play at half volume. Every sound in the Effects class would have its pitch doubled.

First, you will create the Sound Classes.

Creating the Sound Classes

In this tutorial, you will adjust the volume of the music and effects independently. This means you will need two Sound Classes. In the Content Browser, click Add New and select Sounds\Sound Class. Rename the Sound Class to S_Music_Class.

Create another Sound Class and name it S_Effects_Class.

Unreal Engine 4 Audio Tutorial

Next, you need to assign each sound to a Sound Class. First, you will do it for the music. Open S_Music and then locate the Sound section. Change Sound Class to S_Music_Class.

Unreal Engine 4 Audio Tutorial

Once you have done that, close S_Music.

Next up are the sound effects. Instead of opening each sound up and assigning a Sound Class, you can do it all at once. First, select the following assets:

  • S_Footstep
  • S_Pop_Cue
  • S_Rain

Afterwards, right-click on one of the selected assets. Select Asset Actions\Bulk Edit via Property Matrix. This will open the assets in the property matrix editor.

Unreal Engine 4 Audio Tutorial

The property matrix editor allows you to edit common properties at the same time.

Go to the Details panel and expand the Sound branch. To select a Sound Class, click the grid icon to the right of Sound Class.

Unreal Engine 4 Audio Tutorial

Select S_Effects_Class and then close the property matrix editor.

All the sounds are now in their appropriate Sound Class. Next, you will create a Sound Mix and adjust it using Blueprints.

Creating and Adjusting a Sound Mix

In the Content Browser, click Add New and select Sounds\Sound Mix. Rename the Sound Mix to S_Volume_Mix.

To control the volume of each Sound Class, you will use sliders. I’ve already created a widget with two sliders for you to use. Navigate to the UI folder and open WBP_Options.

Unreal Engine 4 Audio Tutorial

To adjust the volume, you need to use the value from these sliders and feed it into the Sound Mix. You will do this for the music first.

Switch to the Graph mode and then go to the My Blueprints panel. Under the Variables section, select MusicSlider. Go to the Details panel and click the button next to On Value Changed.

Unreal Engine 4 Audio Tutorial

This will create the On Value Changed (MusicSlider) event. This event fires whenever you move the slider handle.

Unreal Engine 4 Audio Tutorial

Now, you need to set the volume of S_Music_Class within S_Volume_Mix. To do this, you need to use a Set Sound Mix Class Override node. This node allows you to specify a Sound Mix and a Sound Class. If the Sound Class is not in the Sound Mix, it will be added. If it is already in the Sound Mix, it will update.

Add a Set Sound Mix Class Override node and set the following options:

  • In Sound Mix Modifier: S_Volume_Mix
  • In Sound Class: S_Music_Class
  • Fade in Time: 0 (This will make sure the volume adjustments are instantenous)

Unreal Engine 4 Audio Tutorial

Next, connect your nodes like so:

Unreal Engine 4 Audio Tutorial

Repeat the steps for EffectsSlider. Change the In Sound Class pin to S_Effects_Class.

Unreal Engine 4 Audio Tutorial

Now, whenever the value of a slider changes, S_Volume_Mix will adjust the volume of the relevant Sound Class.

Before any of this will work, you need to activate the Sound Mix.

Tommy Tran

Contributors

Tommy Tran

Author

Over 300 content creators. Join our team.