In this guide we will be looking at adding audio attenuation into your Unreal Engine 4 game.
The Attenuation Class
Creating the Class
To create a sound attenuation class, right click anywhere in your content browser, navigate to the sounds section and click Sound Attenuation.
Give your new Sound Attenuation class a name and remember it as we will be using it later in the guide.
I named mine Tutorial Sound Attenuation.
Opening your new Sound Attenuation class will show these settings:
There are many settings that can be changed to modulate your audio to make it very realistic.
For simple audio attenuation we only need these settings:
For the demonstration video at the end of the guide I will be using these exact settings.
The attenuation function determines how the volume is changed over distance.
- Linear reduces the volume equal to the distance.
- Logarithmic reduces the volume much faster over distance.
- Inverse has the fastest volume drop off.
- Log Reverse reduces the volume very slowly until a large distance then it drops off very quickly.
- Natural sound reduces the volume to imitate how sound works in the real world.
- Custom is for creating your own curves. This isn’t recommended as it can get quite complicated.
For the majority of your sounds I recommend to use the Logarithmic function. It creates easily locatable sound and prevents far sounds from being unnecessarily loud.
Attenuation shapes restrict sounds to a specific shape. This prevents sounds from leaking out of a specific environment.
- Sphere is for most sounds.
- Capsule is for thin and round environments.
- Box is for cuboid shaped buildings.
- Cone is for projecting sound at a specific area or player.
The inner radius is the size of the sphere that represents your sound at full volume.
Any player inside this sphere will hear the sound without any volume reduction.
The falloff distance is the distance the player needs to be for the audio volume to be zero.
The volume reaches zero using the attenuation function setup earlier.
Enable Volume Attenuation
This setting controls if you want the audio to lower in volume over distance. We need this to be checked.
Applying the Attenuation Class
To play sounds with your newly setup attenuation class, create a “Play Sound at Location” node.
Set the Sound input pin to which ever sound file you want to play.
Create a “Get Actor Location” node and connect it to the Location pin on the “Play Sound at Location” node.
Click the box with the triangle to expose the additional audio settings.
The additional setting that we need is called “Attenuation Settings”. Set this to your attenuation class created at the start of the guide.
Now your sound will use the Sound Attenuation class when played and will be specialized in the world at the location specified.
These are just the basics of attenuation in Unreal Engine 4. I recommend spending time to figure out which is the best attenuation function and attenuation shape for the atmosphere you want to create.
To see the individual plotted graphs for each attenuation function click here for the official Unreal Engine 4 wiki page.