Skip to main content

🎡 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:

  1. In any Blueprint, right-click and search for Play Sound 2D
  2. Connect the execution pin to your trigger event
  3. Set the Sound input to your Sound Wave, Sound Cue, or MetaSound
  4. 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)
Play Sound 2D Blueprint Node On Button Clicked (UI Event) Play Sound 2D Exec Sound: SW_UI_Click Volume: 1.0 Pitch: 1.0 Result Sound plays immediately 2D audio: Same volume everywhere, no spatialization

Figure: Play Sound 2D triggered by a button click event.

Example: UI Button Click Sound

In a Widget Blueprint:

  1. Select your Button widget
  2. In Details, scroll to Events β†’ click + next to On Clicked
  3. In the Event Graph, drag from the On Clicked event
  4. Add Play Sound 2D node
  5. 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

  1. Right-click in Blueprint and search for Play Sound at Location
  2. Connect the execution pin to your trigger
  3. Set the Sound input
  4. Provide a Location vector (world space position)
  5. 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)
Play Sound at Location Example Get Actor Location (Self) Play Sound at Location Exec Sound: SC_Explosion Location ← Attenuation: SA_Explosion World Space P Listener πŸ’₯ Sound spawns at explosion location 3D audio: Volume/panning based on listener position relative to sound location

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):

  1. Select an Actor in the level or open an Actor Blueprint
  2. In Components panel, click Add
  3. Search for and add Audio
  4. 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):

  1. Use Spawn Sound 2D or Spawn Sound at Location
  2. These return an Audio Component reference
  3. 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
Audio Component on Actor BP_Torch (Actor) πŸ“¦ Static Mesh (Torch model) πŸ”₯ Particle System (Fire) πŸ”Š Audio Component Moves with actor Audio Component Details Sound: SC_FireLoop Auto Activate: βœ“ Is UI Sound: βœ— Volume: 1.0 Pitch: 1.0 Attenuation: SA_Fire In World Looping fire sound

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

Sound Playback Decision Guide Need 3D positioning? No Play Sound 2D UI, Music, Voice-over Yes Need to control playback? No Play Sound at Location One-shot: Gunshots, Impacts Yes Audio Component Loops, Fades, Moving sources 🎡 2D: Button clicks, BGM πŸ’₯ Location: Explosions, Footsteps πŸ”Š Component: Engines, Ambient

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

  1. Right-click in Content Browser β†’ User Interface β†’ Widget Blueprint
  2. Name it WBP_TestMenu
  3. Open the widget and add a Button to the canvas
  4. Add a Text Block inside the button with text "Click Me"
  5. Name the button TestButton

Step 2: Add Click Event

  1. Select the TestButton
  2. In Details panel, scroll to Events
  3. Click the + next to On Clicked
  4. This creates an event node in the Event Graph

Step 3: Play Sound on Click

  1. In the Event Graph, drag from On Clicked (TestButton)
  2. Search for and add Play Sound 2D
  3. Click the dropdown next to Sound
  4. Select your UI click sound (e.g., SW_UI_Click)

Step 4: Display the Widget

  1. Open your Player Controller or Level Blueprint
  2. On Event BeginPlay:
    • Add Create Widget node
    • Set Class to WBP_TestMenu
    • Add Add to Viewport
  3. Add Set Input Mode UI Only and Set Show Mouse Cursor (True)

Step 5: Test

  1. Play the level
  2. Click the button
  3. You should hear the UI click sound
UI Button Click Sound On Clicked (TestButton) Play Sound 2D Sound: SW_UI_Click Volume: 1.0 Result πŸ”Š Click sound plays 2D audio plays at same volume regardless of player position

Figure: Simple UI click sound using Play Sound 2D.

Part 2: Item Pickup Sound (Play Sound at Location)

Step 6: Create Pickup Actor

  1. Right-click in Content Browser β†’ Blueprint Class β†’ Actor
  2. Name it BP_PickupItem
  3. Open it and add components:
    • Static Mesh (any visible mesh, like a cube or sphere)
    • Sphere Collision (for overlap detection)
  4. Set Sphere Collision radius to 100
  5. Set collision to OverlapAllDynamic

Step 7: Add Overlap Event

  1. Select the Sphere Collision component
  2. In Details, scroll to Events
  3. Click + next to On Component Begin Overlap

Step 8: Check for Player and Play Sound

  1. From the overlap event, add Cast to your Character class
  2. Connect Other Actor to the Cast object pin
  3. 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
  4. After Play Sound at Location, add Destroy Actor

Step 9: Configure Attenuation

  1. The pickup sound needs attenuation to work in 3D
  2. Either:
    • Set attenuation on the Sound Wave/Cue asset, OR
    • Create a Sound Attenuation asset and pass it to the node
  3. For the node: expand Attenuation Settings and select your attenuation asset

Step 10: Test Pickup

  1. Place several BP_PickupItem actors in your level
  2. Play the level
  3. Walk into a pickup
  4. Sound should play at the pickup's location, then it disappears
  5. Test from different distances to hear attenuation
Item Pickup Sound Blueprint On Component Begin Overlap Other Actor β†’ Cast To BP_Character Get Actor Location Play Sound at Location Sound: SC_Pickup Location ← Destroy Actor (Self) Sound plays at pickup location, audible based on player distance

Figure: Pickup item plays 3D sound at its location before being destroyed.

Part 3: Looping Torch Sound (Audio Component)

Step 11: Create Torch Actor

  1. Right-click in Content Browser β†’ Blueprint Class β†’ Actor
  2. Name it BP_Torch
  3. Open it and add components:
    • Static Mesh (torch or cylinder shape)
    • Point Light (orange/yellow, flicker optional)
    • Audio component

Step 12: Configure Audio Component

  1. Select the Audio component
  2. 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:

  1. Right-click β†’ Sounds β†’ Sound Attenuation
  2. Name it SA_Fire
  3. 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

  1. Place BP_Torch actors in your level
  2. Play the level
  3. Walk toward a torch β€” fire sound gets louder
  4. Walk away β€” sound fades
  5. Walk around it β€” sound pans left/right

Part 4: Controllable Torch (Toggle Sound)

Step 15: Add Toggle Functionality

  1. Open BP_Torch
  2. Add a variable: bIsLit (Boolean, default True)
  3. Create a custom event: ToggleTorch

Step 16: Implement Toggle Logic

  1. 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

  1. Add a Box Collision component to the torch (interaction zone)
  2. In your Character Blueprint, add input for "Interact" (E key)
  3. On interact:
    • Line trace forward from camera
    • If hit actor is BP_Torch β†’ Call ToggleTorch
  4. Or use a simpler overlap approach for this exercise
Toggle Torch Audio Control ToggleTorch Flip Flop A β†’ B β†’ Turn Off Audio β†’ Stop Light β†’ Hidden Turn On Audio β†’ Play Light β†’ Visible Result πŸ”Š ON πŸ”‡ OFF

Figure: Audio Component controlled by toggle event.

Part 5: Bonus - Fade Music on Pause

Step 18: Set Up Background Music

  1. In your Player Controller or Game Mode
  2. Add a variable: MusicComponent (Audio Component reference)
  3. On Begin Play:
    • Spawn Sound 2D with your music track
    • Store the returned Audio Component in MusicComponent

Step 19: Fade on Pause

  1. 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
  2. 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

  1. Footstep Sounds: Add footstep sounds to your character using Animation Notifies
  2. Random Pitch: Use your randomized footstep Sound Cue from Lesson 8.1
  3. Weapon Sounds: Add fire and reload sounds to a weapon Blueprint
  4. Door Sounds: Play open/close sounds on an interactable door
  5. Health Pickup: Play a healing sound when collecting health
  6. Low Health Warning: Play a looping heartbeat when health is critical
  7. 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
Sound Playback Methods Summary Play Sound 2D Non-positional Fire and forget 🎡 UI β€’ Music β€’ VO Play Sound at Location 3D positioned One-shot, static πŸ’₯ Explosions β€’ Impacts Audio Component 3D, moves with actor Full playback control πŸ”Š Loops β€’ Engines β€’ Fades Decision Process Need 3D? β†’ No: 2D | Yes β†’ Need control? β†’ No: Location | Yes: Component

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.