UGameplayStatics::SpawnSound2D
#include "Kismet/GameplayStatics.h"
Access: public
Specifiers: staticUFUNCTIONBlueprintCallableBlueprintCosmetic
Description
Spawns an audio component that plays a non-spatialized (2D) sound with no attenuation. Ideal for UI sounds, music stingers, and announcer audio that should play at full volume regardless of the listener's position.
Caveats & Gotchas
- • Unlike PlaySound2D, this function returns a UAudioComponent so you can pause, stop, or adjust the sound after spawning — use this when you need control over the playback lifecycle.
- • BlueprintCosmetic — this is client-side only. Sounds will not play on a dedicated server. Ensure you call this from client-side code (BeginPlay on a HUD/widget, or a cosmetic-only path).
- • bPersistAcrossLevelTransition works by moving the component to the persistent world — if you use this, remember to manually destroy the component or stop playback when it is no longer needed to avoid audio leaks.
Signature
static ENGINE_API UAudioComponent* SpawnSound2D(const UObject* WorldContextObject, USoundBase* Sound, float VolumeMultiplier = 1.f, float PitchMultiplier = 1.f, float StartTime = 0.f, USoundConcurrency* ConcurrencySettings = nullptr, bool bPersistAcrossLevelTransition = false, bool bAutoDestroy = true); Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| WorldContextObject | const UObject* | Object used to retrieve the world context. | — |
| Sound | USoundBase* | The sound asset to play. | — |
| VolumeMultiplier | float | Volume scale applied on top of the sound's base volume. | 1.f |
| PitchMultiplier | float | Pitch scale applied to the sound. | 1.f |
| StartTime | float | Offset into the sound to begin playback, in seconds. | 0.f |
| ConcurrencySettings | USoundConcurrency* | Optional concurrency asset controlling how many instances can play simultaneously. | nullptr |
| bPersistAcrossLevelTransition | bool | If true, the audio component is not destroyed during level transitions. | false |
| bAutoDestroy | bool | If true, the audio component is destroyed when playback finishes. | true |
Return Type
UAudioComponent* Example
Play a UI confirm sound and get back the component C++
UAudioComponent* ConfirmAudio = UGameplayStatics::SpawnSound2D(
this,
ConfirmSoundAsset,
1.0f, // VolumeMultiplier
1.0f, // PitchMultiplier
0.f, // StartTime
nullptr, // ConcurrencySettings
false, // bPersistAcrossLevelTransition
true // bAutoDestroy
);
// ConfirmAudio can be used to stop playback early if needed Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?