RealDocs

UGameplayStatics::SpawnSoundAttached

function Engine Blueprint Since 4.0
#include "Kismet/GameplayStatics.h"
Access: public Specifiers: staticUFUNCTIONBlueprintCallable

Description

Spawns a spatialized UAudioComponent attached to a scene component so it follows it through the world. Playback begins immediately.

Caveats & Gotchas

  • If AttachToComponent is nullptr the function returns nullptr silently; always validate the component before calling.
  • bStopWhenAttachedToDestroyed defaults to false, so sounds can continue playing as orphaned components after the parent is destroyed — set it to true for character death sounds to avoid audio leaks.
  • Replication is not handled; for multiplayer games, trigger this on clients via a multicast RPC or a replicated variable.

Signature

static ENGINE_API UAudioComponent* SpawnSoundAttached(USoundBase* Sound, USceneComponent* AttachToComponent, FName AttachPointName = NAME_None, FVector Location = FVector(ForceInit), FRotator Rotation = FRotator::ZeroRotator, EAttachLocation::Type LocationType = EAttachLocation::KeepRelativeOffset, bool bStopWhenAttachedToDestroyed = false, float VolumeMultiplier = 1.f, float PitchMultiplier = 1.f, float StartTime = 0.f, USoundAttenuation* AttenuationSettings = nullptr, USoundConcurrency* ConcurrencySettings = nullptr, bool bAutoDestroy = true)

Parameters

Name Type Description Default
Sound USoundBase* The sound asset to play.
AttachToComponent USceneComponent* The component to attach the audio component to.
AttachPointName FName Optional socket or bone name on the component to attach at. NAME_None
Location FVector Location offset relative to the attach point. FVector(ForceInit)
Rotation FRotator Rotation offset relative to the attach point. FRotator::ZeroRotator
LocationType EAttachLocation::Type Whether Location is relative or world-space. EAttachLocation::KeepRelativeOffset
bStopWhenAttachedToDestroyed bool Stop playback when the component it is attached to is destroyed. false
VolumeMultiplier float Linear scalar applied to the volume. 1.f
PitchMultiplier float Linear scalar applied to the pitch. 1.f
StartTime float Offset in seconds into the sound to begin playback. 0.f
AttenuationSettings USoundAttenuation* Optional attenuation override asset. nullptr
ConcurrencySettings USoundConcurrency* Optional concurrency settings override. nullptr
bAutoDestroy bool Automatically destroy the audio component when the sound finishes. true

Return Type

UAudioComponent*

Example

Attach engine loop to a vehicle mesh C++
UAudioComponent* EngineAudio = UGameplayStatics::SpawnSoundAttached(
	EngineLoopSound,
	GetMesh(),
	NAME_None,
	FVector::ZeroVector,
	FRotator::ZeroRotator,
	EAttachLocation::KeepRelativeOffset,
	true);
if (EngineAudio)
{
	EngineAudio->SetFloatParameter(FName("RPM"), CurrentRPM);
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.