π΅ Playing Sounds
Now that you understand audio assets, it's time to make some noise! This lesson teaches you how to trigger sounds from Blueprintsβwhether it's a UI click, a gunshot at a specific location, or an ambient sound attached to an actor. You'll learn the right tool for each situation.
π― Learning Objectives
By the end of this lesson, you will be able to:
- Use Play Sound 2D for UI and non-positional audio
- Use Play Sound at Location for 3D positioned sounds
- Add Audio Components to actors for persistent sounds
- Control audio playback from Blueprints
- Choose the right playback method for each use case
Estimated Time: 30-40 minutes
Prerequisites: Lesson 8.1 (Sound in Unreal)
π In This Lesson
Play Sound 2D
Play Sound 2D is the simplest way to play audio. It plays a sound without any 3D positioningβthe audio comes through at full volume regardless of where anything is in the world. Perfect for sounds that exist "outside" the game space.
When to Use Play Sound 2D
- UI sounds: Button clicks, menu navigation, notifications
- Music: Background music, victory/defeat stingers
- Voice-over: Narrator, tutorial instructions
- System sounds: Achievement unlocked, save complete
- Non-diegetic audio: Sounds the player hears but characters don't
Using Play Sound 2D in Blueprints
The node is straightforward:
- In any Blueprint, right-click and search for Play Sound 2D
- Connect the execution pin to your trigger event
- Set the Sound input to your Sound Wave, Sound Cue, or MetaSound
- Optionally adjust Volume Multiplier and Pitch Multiplier
Node Parameters
| Parameter | Type | Description |
|---|---|---|
| Sound | USoundBase | The sound to play (Wave, Cue, or MetaSound) |
| Volume Multiplier | Float | Scales the sound's volume (default 1.0) |
| Pitch Multiplier | Float | Scales the pitch/speed (default 1.0) |
| Start Time | Float | Time offset to start playback (seconds) |
| Concurrency Settings | Object | Override concurrency behavior (advanced) |
Figure: Play Sound 2D triggered by a button click event.
Example: UI Button Click Sound
In a Widget Blueprint:
- Select your Button widget
- In Details, scroll to Events β click + next to On Clicked
- In the Event Graph, drag from the On Clicked event
- Add Play Sound 2D node
- Set Sound to your UI click sound
π‘ Fire and Forget
Play Sound 2D is "fire and forget"βyou trigger it and it plays to completion. You don't get a reference to control it later. If you need to stop, pause, or modify a playing sound, use an Audio Component instead.
Play Sound at Location
Play Sound at Location spawns a 3D sound at a specific world position. The sound is spatializedβvolume and panning change based on the listener's position relative to where the sound was spawned. This is ideal for one-shot effects in the game world.
When to Use Play Sound at Location
- Explosions: Sound at the explosion point
- Gunshots: Sound at the weapon's muzzle
- Footsteps: Sound at the character's feet
- Impacts: Bullet hits, object collisions
- Pickups: Item collection sounds
- One-shot environmental: Door slam, switch flip
Using Play Sound at Location
- Right-click in Blueprint and search for Play Sound at Location
- Connect the execution pin to your trigger
- Set the Sound input
- Provide a Location vector (world space position)
- Optionally set Rotation for directional sounds
Node Parameters
| Parameter | Type | Description |
|---|---|---|
| Sound | USoundBase | The sound to play |
| Location | Vector | World position to spawn the sound |
| Rotation | Rotator | Orientation (for directional sounds) |
| Volume Multiplier | Float | Scales volume (default 1.0) |
| Pitch Multiplier | Float | Scales pitch (default 1.0) |
| Start Time | Float | Offset into the sound |
| Attenuation Settings | Object | Override attenuation (or use sound's default) |
Figure: Play Sound at Location spawns 3D audio at a world position.
Getting the Location
Common ways to get the location for your sound:
Actor's Location:
Get Actor Location β Play Sound at Location
Component's Location:
Get World Location (Component) β Play Sound at Location
Hit Result Location:
Line Trace β Break Hit Result β Impact Point β Play Sound at Location
Spawn Location:
Spawn Actor β Get Actor Location β Play Sound at Location
β οΈ Attenuation Required
For 3D sounds to work properly, the sound needs attenuation settings. Either set them on the Sound Wave/Cue asset, or pass a Sound Attenuation asset to the node's Attenuation Settings parameter. Without attenuation, the sound won't fade with distance.
Audio Components
Audio Components are the most versatile way to play sounds. Unlike the "fire and forget" nodes, Audio Components give you a persistent reference to control playbackβplay, stop, pause, adjust volume, and more. They're attached to actors and move with them.
When to Use Audio Components
- Looping sounds: Engine hum, ambient fire, machinery
- Controllable audio: Music that needs to stop/fade
- Moving sound sources: Vehicle engine, flying projectile
- Sounds needing runtime adjustment: Volume/pitch changes
- Persistent environmental audio: Waterfall, torch, air conditioner
Adding an Audio Component
In the Editor (Static):
- Select an Actor in the level or open an Actor Blueprint
- In Components panel, click Add
- Search for and add Audio
- Configure in Details panel:
- Set Sound to your audio asset
- Enable Auto Activate if it should play on spawn
- Set Attenuation Settings for 3D behavior
In Blueprints (Dynamic):
- Use Spawn Sound 2D or Spawn Sound at Location
- These return an Audio Component reference
- Store the reference to control later
Audio Component Properties
| Property | Description |
|---|---|
| Sound | The sound asset to play |
| Auto Activate | Play automatically when spawned/level starts |
| Is UI Sound | Play as 2D (ignores listener position) |
| Volume Multiplier | Scale the base volume |
| Pitch Multiplier | Scale the base pitch |
| Attenuation Settings | Override 3D behavior |
| Attenuation Overrides | Per-instance attenuation tweaks |
Figure: Audio Component attached to a torch actor for persistent fire sound.
Controlling Audio Components
Audio Components provide functions for runtime control:
| Function | Purpose |
|---|---|
| Play | Start or resume playback |
| Stop | Stop playback immediately |
| Set Paused | Pause/unpause (retains position) |
| Is Playing | Check if currently playing |
| Set Volume Multiplier | Change volume at runtime |
| Set Pitch Multiplier | Change pitch at runtime |
| Set Sound | Change the sound asset |
| Fade In / Fade Out | Gradual volume changes |
| Adjust Volume | Fade to target volume over time |
Example: Fading Music
// In Level Blueprint or Game Mode
// Store reference to music Audio Component
// To fade out music over 2 seconds:
MusicComponent β Fade Out (Fade Out Duration: 2.0, Fade Volume Level: 0.0)
// To fade in music over 1 second:
MusicComponent β Fade In (Fade In Duration: 1.0, Fade Volume Level: 1.0)
flowchart LR
A[Spawn Actor] --> B{Auto Activate?}
B -->|Yes| C[Playing]
B -->|No| D[Stopped]
D -->|Play| C
C -->|Stop| D
C -->|Set Paused true| E[Paused]
E -->|Set Paused false| C
C -->|Fade Out| F[Fading Out]
F --> D
D -->|Fade In| G[Fading In]
G --> C
style C fill:#4CAF50,color:#fff
style D fill:#666,color:#fff
style E fill:#FF9800,color:#fff
Figure: Audio Component state transitions.
Choosing the Right Method
With three ways to play sounds, choosing the right one ensures clean code and optimal performance.
Quick Decision Guide
Figure: Decision tree for choosing the right playback method.
Comparison Table
| Feature | Play Sound 2D | Play Sound at Location | Audio Component |
|---|---|---|---|
| 3D Positioning | β No | β Yes | β Yes (optional) |
| Control After Play | β No | β No | β Yes |
| Moves with Actor | N/A | β No (static) | β Yes |
| Looping | β οΈ Limited | β οΈ Limited | β Full support |
| Best For | UI, Music | One-shot SFX | Persistent audio |
| Setup Complexity | Minimal | Minimal | Moderate |
Common Patterns
Pattern 1: UI Feedback
Button OnClicked β Play Sound 2D (UI Click)
Pattern 2: Weapon Fire
Fire Weapon β Get Muzzle Location β Play Sound at Location (Gunshot)
Pattern 3: Character Footsteps
Animation Notify β Get Foot Bone Location β Play Sound at Location (Footstep Cue)
Pattern 4: Vehicle Engine
Vehicle Blueprint:
- Audio Component (Engine Sound)
- On Tick: Set Pitch based on RPM
Pattern 5: Background Music
Game Mode Begin Play:
- Spawn Sound 2D (Music) β Store Reference
- On Level Complete: Fade Out β Play Victory Sting
β Best Practice
Start with the simplest option that meets your needs. Use Play Sound 2D for UI, Play Sound at Location for one-shots, and only reach for Audio Components when you need control or persistence. This keeps your Blueprints clean and performant.
Hands-On: Adding Sound Effects to Interactions
Let's wire up audio to gameplay events. You'll add UI sounds, interaction sounds, and environmental audio using all three playback methods. This exercise builds on what you created in Lesson 8.1.
π― Exercise Goal
Add sound effects to a button click (2D), an item pickup (3D at location), and a looping fire torch (Audio Component). You'll practice choosing the right method for each situation.
Prerequisites
Before starting, ensure you have:
- Sound assets from Lesson 8.1 (or import new ones)
- A playable level with a character
- Basic knowledge of Widget Blueprints (from Module 7)
Part 1: UI Button Click Sound (Play Sound 2D)
Step 1: Create a Simple UI Widget
- Right-click in Content Browser β User Interface β Widget Blueprint
- Name it
WBP_TestMenu - Open the widget and add a Button to the canvas
- Add a Text Block inside the button with text "Click Me"
- Name the button
TestButton
Step 2: Add Click Event
- Select the TestButton
- In Details panel, scroll to Events
- Click the + next to On Clicked
- This creates an event node in the Event Graph
Step 3: Play Sound on Click
- In the Event Graph, drag from On Clicked (TestButton)
- Search for and add Play Sound 2D
- Click the dropdown next to Sound
- Select your UI click sound (e.g.,
SW_UI_Click)
Step 4: Display the Widget
- Open your Player Controller or Level Blueprint
- On Event BeginPlay:
- Add Create Widget node
- Set Class to
WBP_TestMenu - Add Add to Viewport
- Add Set Input Mode UI Only and Set Show Mouse Cursor (True)
Step 5: Test
- Play the level
- Click the button
- You should hear the UI click sound
Figure: Simple UI click sound using Play Sound 2D.
Part 2: Item Pickup Sound (Play Sound at Location)
Step 6: Create Pickup Actor
- Right-click in Content Browser β Blueprint Class β Actor
- Name it
BP_PickupItem - Open it and add components:
- Static Mesh (any visible mesh, like a cube or sphere)
- Sphere Collision (for overlap detection)
- Set Sphere Collision radius to 100
- Set collision to OverlapAllDynamic
Step 7: Add Overlap Event
- Select the Sphere Collision component
- In Details, scroll to Events
- Click + next to On Component Begin Overlap
Step 8: Check for Player and Play Sound
- From the overlap event, add Cast to your Character class
- Connect Other Actor to the Cast object pin
- From Cast success:
- Add Get Actor Location (Self)
- Add Play Sound at Location
- Set Sound to a pickup sound (create one or use existing)
- Connect location
- After Play Sound at Location, add Destroy Actor
Step 9: Configure Attenuation
- The pickup sound needs attenuation to work in 3D
- Either:
- Set attenuation on the Sound Wave/Cue asset, OR
- Create a Sound Attenuation asset and pass it to the node
- For the node: expand Attenuation Settings and select your attenuation asset
Step 10: Test Pickup
- Place several
BP_PickupItemactors in your level - Play the level
- Walk into a pickup
- Sound should play at the pickup's location, then it disappears
- Test from different distances to hear attenuation
Figure: Pickup item plays 3D sound at its location before being destroyed.
Part 3: Looping Torch Sound (Audio Component)
Step 11: Create Torch Actor
- Right-click in Content Browser β Blueprint Class β Actor
- Name it
BP_Torch - Open it and add components:
- Static Mesh (torch or cylinder shape)
- Point Light (orange/yellow, flicker optional)
- Audio component
Step 12: Configure Audio Component
- Select the Audio component
- In Details panel, configure:
- Sound: Your fire/torch loop sound
- Auto Activate: β (checked)
- Is UI Sound: β (unchecked β we want 3D)
- Volume Multiplier: 1.0
- Attenuation Settings: Select your fire attenuation asset
Step 13: Create Fire Sound Attenuation
If you don't have a fire attenuation asset:
- Right-click β Sounds β Sound Attenuation
- Name it
SA_Fire - Configure:
- Inner Radius: 50 (close to hear full volume)
- Falloff Distance: 800 (audible from moderate distance)
- Attenuation Function: Natural Sound
Step 14: Test the Torch
- Place
BP_Torchactors in your level - Play the level
- Walk toward a torch β fire sound gets louder
- Walk away β sound fades
- Walk around it β sound pans left/right
Part 4: Controllable Torch (Toggle Sound)
Step 15: Add Toggle Functionality
- Open
BP_Torch - Add a variable:
bIsLit(Boolean, default True) - Create a custom event:
ToggleTorch
Step 16: Implement Toggle Logic
- In the ToggleTorch event:
- Add Flip Flop node
- On A (turning off):
- Set bIsLit = False
- Audio Component β Stop
- Point Light β Set Visibility (False)
- On B (turning on):
- Set bIsLit = True
- Audio Component β Play
- Point Light β Set Visibility (True)
Step 17: Trigger from Player Interaction
- Add a Box Collision component to the torch (interaction zone)
- In your Character Blueprint, add input for "Interact" (E key)
- On interact:
- Line trace forward from camera
- If hit actor is BP_Torch β Call ToggleTorch
- Or use a simpler overlap approach for this exercise
Figure: Audio Component controlled by toggle event.
Part 5: Bonus - Fade Music on Pause
Step 18: Set Up Background Music
- In your Player Controller or Game Mode
- Add a variable:
MusicComponent(Audio Component reference) - On Begin Play:
- Spawn Sound 2D with your music track
- Store the returned Audio Component in MusicComponent
Step 19: Fade on Pause
- When opening pause menu:
- MusicComponent β Set Volume Multiplier (0.3) for quick duck
- Or use Adjust Volume (Target: 0.3, Duration: 0.5) for fade
- When closing pause menu:
- MusicComponent β Set Volume Multiplier (1.0)
- Or Adjust Volume (Target: 1.0, Duration: 0.5)
β Exercise Complete!
You've implemented:
- Play Sound 2D: UI button click feedback
- Play Sound at Location: 3D pickup collection sound
- Audio Component: Persistent looping torch fire
- Audio Control: Toggle and volume adjustment
These patterns cover the majority of sound playback needs in games!
Troubleshooting
β οΈ Common Issues
No sound plays at all:
- Check that Sound asset is assigned
- Verify the sound file imported correctly
- Check master volume in Windows/system
- Check Sound Class isn't muted
3D sound doesn't attenuate:
- Ensure Attenuation Settings are assigned
- Verify the sound is Mono (stereo won't spatialize)
- Check Falloff Distance is appropriate for your level scale
Audio Component doesn't play:
- Check Auto Activate is enabled, OR
- Call Play explicitly in BeginPlay
- Verify the component isn't being stopped elsewhere
Sound plays but is too quiet/loud:
- Adjust Volume Multiplier on the node/component
- Check the Sound Wave's base volume
- Verify Sound Class volume settings
Looping sound doesn't loop:
- Enable looping in the Sound Wave asset, OR
- Use a Sound Cue with Looping node
Bonus Challenges
- Footstep Sounds: Add footstep sounds to your character using Animation Notifies
- Random Pitch: Use your randomized footstep Sound Cue from Lesson 8.1
- Weapon Sounds: Add fire and reload sounds to a weapon Blueprint
- Door Sounds: Play open/close sounds on an interactable door
- Health Pickup: Play a healing sound when collecting health
- Low Health Warning: Play a looping heartbeat when health is critical
- Menu Music: Different music for main menu vs gameplay
Summary
In this lesson, you've learned the three primary methods for playing sounds in Unreal Engine. Choosing the right method for each situation keeps your audio code clean and your game performant.
Key Concepts
Play Sound 2D: The simplest methodβplays audio without 3D positioning. Same volume everywhere, no panning or distance attenuation. Use for UI sounds, music, voice-over, and any audio that exists "outside" the game world. Fire-and-forget with no playback control.
Play Sound at Location: Spawns a 3D sound at a specific world position. Volume and panning change based on listener position. Requires mono audio and attenuation settings for proper spatialization. Use for one-shot effects like explosions, gunshots, and impacts. Also fire-and-forget.
Audio Components: The most versatile optionβattach to actors for persistent, controllable audio. Supports play, stop, pause, fade, and runtime volume/pitch adjustment. Moves with the owning actor. Use for looping sounds, moving sound sources, and any audio needing runtime control.
Choosing the Right Method: Start with the simplest option that meets your needs. 2D for non-positional audio, Location for one-shots in the world, Components for everything that needs persistence or control.
Method Quick Reference
| Method | 3D | Control | Best For |
|---|---|---|---|
| Play Sound 2D | β | β | UI, Music, Voice-over |
| Play Sound at Location | β | β | Explosions, Gunshots, Pickups |
| Audio Component | β | β | Loops, Engines, Ambient, Fades |
Audio Component Functions
| Function | Purpose |
|---|---|
| Play | Start or resume playback |
| Stop | Stop playback immediately |
| Set Paused | Pause without losing position |
| Is Playing | Check playback state |
| Set Volume/Pitch Multiplier | Instant value change |
| Fade In / Fade Out | Gradual volume transitions |
| Adjust Volume | Fade to target over duration |
Common Patterns
UI Feedback: Button Click β Play Sound 2D
Weapon Fire: Get Muzzle Location β Play Sound at Location
Item Pickup: Get Actor Location β Play Sound at Location β Destroy Actor
Environmental Loop: Actor with Audio Component (Auto Activate, Looping)
Vehicle Engine: Audio Component + Tick β Set Pitch based on speed/RPM
Music Control: Spawn Sound 2D β Store Reference β Fade In/Out as needed
Best Practices
- Use the simplest method: Don't use Audio Components when Play Sound 2D would suffice
- Mono for 3D: Always use mono audio files for spatialized sounds
- Configure attenuation: 3D sounds need attenuation settings to fade with distance
- Store references: If you need to control audio later, keep the Audio Component reference
- Clean up: Stop looping sounds when their owning actor is destroyed
- Use Sound Cues: For variation, layer through a Sound Cue rather than multiple nodes
- Test in-game: Audio behavior can differ between editor preview and actual gameplay
Figure: Three methods for different audio playback scenarios.
What's Next?
Now that you can trigger sounds from Blueprints, the next lesson covers Ambient Audio. You'll learn about Ambient Sound actors for easy level audio, Audio Volumes for reverb zones, and strategies for creating immersive environmental soundscapes.
Knowledge Check
Question 1
Which playback method should you use for a UI button click sound?
Correct answer: B β Play Sound 2D is perfect for UI sounds because they don't need 3D positioning. The click should sound the same regardless of where the player is in the world.
Question 2
What is required for Play Sound at Location to properly spatialize audio?
Correct answer: B β 3D spatialization requires mono audio (stereo has fixed channels that can't pan correctly) and attenuation settings to control how the sound fades with distance.
Question 3
When should you use an Audio Component instead of Play Sound at Location?
Correct answer: C β Audio Components are necessary when you need runtime control (stop, pause, volume adjustment, fading) or when the sound source moves (like a vehicle engine). For simple one-shot effects at a fixed location, Play Sound at Location is simpler and sufficient.
Question 4
What does the "Auto Activate" property do on an Audio Component?
Correct answer: B β Auto Activate causes the Audio Component to start playing immediately when it's created (spawned) or when the level begins. Without this enabled, you must call Play() explicitly to start the sound.
Question 5
How do you gradually reduce an Audio Component's volume over time?
Correct answer: B β Use Fade Out (fades to zero and optionally stops) or Adjust Volume (fades to any target level) with a specified duration. These handle the interpolation automatically without needing manual loops.
Question 6
Which is the correct pattern for playing a sound when an item is picked up?
Correct answer: B β Get the item's location, play the 3D sound at that position, then destroy the actor. The sound continues playing even after the actor is destroyed because Play Sound at Location spawns an independent sound instance.
Question 7
What happens to a sound started with Play Sound at Location when the triggering actor is destroyed?
Correct answer: B β Play Sound at Location spawns an independent sound instance in the world. It's not attached to any actor, so destroying the actor that triggered it has no effect on the sound. The sound plays to completion at its spawned location.