Sound Attenuation


Create a new project

Prerequisites: You will need to download Unreal Engine 4.25 to follow along with this tutorial

1. Open Epic Games Launcher and click on Launch Unreal Engine 4

Unreal Engine 4 Launch Button in Epic Games Launcher

2. Create a new project and select Games from the project categories then click Next

Unreal Engine 4 New Project Categories Games

3. Select Third Person then click Next

Unreal Engine 4 Select Template

4. Choose Blueprints, with Starter Content (You can change the project settings to fit your project) in this case, the target platform is Desktop/Console. Choose a location to store your project, name your project and then click Create Project

Unreal Engine 4 Project Settings

Project setup

1. From the Main Menu Bar at the top, click on File > New Level

Unreal Engine 4 Level Editor, Main Menu Bar, File

2. Choose Default Level. Save your level/map in the same folder as the ThirdPersonExampleMap which is in the ThirdPersonBP folder in the Maps folder

Unreal Engine 4 Level Editor, New Level Pop Up Window Unreal Engine 4 Level Editor, Default Level

3. Right click in the Content Browser down at the bottom and create 2 new folders - Fire and Sounds

Unreal Engine 4 Content Browser

4. In the Fire folder, right click and create a new Actor Blueprint Class and name it FireBP

Unreal Engine 4 New Blueprint Class Unreal Engine 4 New Blueprint Class Pop Up Window, Actor

Fire particle setup

1. Double click on FireBP to open it up in the Blueprint Editor. Click on DefaultSceneRoot then click on Add Component > Particle System

Unreal Engine 4 Blueprint Editor, Add Component, Particle System

2. Click on the newly added Particle System and on the right in the Details panel, under Particles > Template choose TutorialParticleSystem

Unreal Engine 4 Blueprint Editor, Details Panel, Particles, Template

If you don't see TutorialParticleSystem in Template, click on View Options at the bottom and make sure Show Engine Content is ticked

Unreal Engine 4 Blueprint Editor, Details Panel, Particles, Template, View Option

3. In the Details panel, under Transform > Location - set the Z-axis to be more than 0 so that the particles are above the ground. Feel free to scale it to your liking, the default is 1.0 on all 3 axis

Unreal Engine 4 Blueprint Editor, Details Panel, Transform

Remember to hit Compile and Save before switching back to the Level Editor

Unreal Engine 4 Blueprint Editor, Menu Bar, Compile & Save

4. Back in the Level Editor, drag and drop the FireBP from the Content Browser into the level (You can scale the Floor so that it's bigger)

Unreal Engine 4 Level Editor, Level

Sound setup

Prerequisites: Download the campfire sound here
For Mac users
(The sound is from the free Soundly cloud library)

1. Go to the previously created Sounds folder, right click and click Import Asset. Locate to where you saved the wav file. Alternatively, you can drag and drop the wav file into the Sounds folder

If you're on Mac, make sure the wav file is 16-bit. Unfortunately, the wav file provided is 24-bit but you can easily convert it in your DAW (Digital Audio Workstation) or online

Unreal Engine 4 Content Browser, Import Asset

2. Right click on the newly added wav file and click Create Cue - A new Sound Cue will be created (Feel free to rename it or leave it as is)

Unreal Engine 4 Content Browser, Sound Cue

3. Double click on the sound cue to open it up in the Sound Cue Editor. Click on Looping Wave Player and under the Details Panel on the left, make sure Looping is ticked. Don't forget to hit Save before closing the Sound Cue Editor

Unreal Engine 4 Sound Cue Editor

Attenuation settings

1. Go back to the FireBP Blueprint editor and under the DefaultSceneRoot add an Audio component

Unreal Engine 4 Blueprint Editor, Add Component, Audio

2. Click on the Audio component and in the Details panel under Sound, add the Sound Cue (not the Sound Wave)

Unreal Engine 4 Blueprint Editor, Details, Sound

3. In the Details panel, scroll to Attenuation and tick Override Attenuation

Unreal Engine 4 Blueprint Editor - Details - Attenuation

4. In the same Details panel, scroll to Attenuation Distance and tick Enable Volume Attenuation

Unreal Engine 4 Blueprint Editor, Enable Volume Attenuation checkbox

5. You can set the attenuation shape which is used to define the minimum and maxium attenuation points of the sound. In our case, we're using a sphere. The inner radius is where the sound will be at maximum volume (completely unattenuated). The falloff distance defines the size of the outer area of the attenuation shape. Make sure Enable Volume Attenuation is ticked - sound will attenuate/get softer as you get further away from the sound source. If Enable Volume Automation is unticked - sound will play at full volume regardless of where the Player is from the sound source

Unreal Engine 4 Blueprint Editor, Attenuation Shape

6. Attenuation Function determines the rate of attenuation over distance. There are a number of different attenuation curves and here are the ones listed:
Linear - volume attenuates linearly which means the changes in volume are constant

Linear Curve Graph

Logarithmic - changes in volume are greater at closer distances, and lesser at far distances

Logarithmic Curve Graph

Inverse - similar to that of Logarithmic curves but more exaggerated

Inverse Curve Graph

Log Reverse - changes in volume are lesser at close distances, essentially the opposite of the Logarithmic curve

Log Reverse Curve Graph

Natural sound - attempts to model a more 'naturalistic' falloff behaviour. It is kind of the middle ground between Logarithmic and Inverse curves

Natural Sound Curve Graph

Custom - you can create your own custom curve which you can create by drawing one directly into the curve editor window, or assign a pre-existing Float Curve asset

Custom Curve Graph

Bonus: Change Audio Listener Position

By default the audio listener is on the camera but we can change it

In this case, we want to use the Character for attenuation and the Camera for panning

Go to the Blueprints folder inside of ThirdPersonBP folder and open up the ThirdPersonCharacter

Unreal Engine 4 Content Browser Third Person BP folder, Blueprints folder, Third Person Character Blueprints

Select the Mesh Component and add a Scene component to it, name it CharListenerPos and in the viewport and position it at the Character's head

Unreal Engine 4 Blueprint Editor, Add Component, Scene Unreal Engine 4 Blueprint Editor, Viewport, CharListenerPos component selected

Click on the Event Graph tab inside the Blueprints Level Editor - this is where we'll create Blueprints

Unreal Engine 4 Third Person Character Blueprints Level Editor, Event Graph

Right click in the Event Graph and add an Event Tick node and Set Audio Listener Override node - Event Tick - updates every frame. Link up the Event Tick node's Out to the Set Audio Listener Override node's In

When searching for a node, make sure the Context Sensitive checkbox is not ticked

Add the Get Player Controller node and link it to the Target in Set Audio Listener Override

Unreal Engine 4 Third Person Character Blueprints Level Editor, Event Graph, Event Tick node and Set Audio Listener Override node linked together, Get Player Controller node linked to Target of Set Audio Listener Override node

Drag and drop the Char Listener Pos component and Follow Camera component into the Event Graph

Then add 2 Get World Location nodes and link the respective components to the targets of the Get World Location nodes

Get World Location returns the location of the component, in world space

Unreal Engine 4 Third Person Character Blueprints Level Editor, Event Graph, Char Listener Pos node linked to Target of Get World Location node, Follow Camera node linked to Target of the other Get World Location node

Next, we want to calculate the rotation value so that the listener rotates according to the camera position relative to the character so we'll use Find Look at Rotation node

We'll use the camera as the Start location and the character as the Target location

Find Look At Rotation - Finds a rotation of an object at the Start location to point at Target location

Unreal Engine 4 Third Person Character Blueprints Level Editor, Event Graph, Char Listener Pos node and Follow Camera node linked to Target of Get World Location nodes respectively, link Return Value of Char Listener Pos node to Target of Find Look at Rotation node, link Return Value of Follow Camera node to Start of Find Look at Rotation node

We're not going to attach the listener to the Character, instead we'll get the location of the Char Listener Pos component

Link the Char Listener Pos's World Location node's Return Value to the Location of the Set Audio Listener Override node

Unreal Engine 4 Third Person Character Blueprints Level Editor, Event Graph, the Get World Location of Char Listener Pos's return value is linked to the Target of Set Audio Listener Override node

Final result (using default audio listener position)