PlaySoundAttached -> SpawnSoundAttached problem

The following deprecated function works fine ingame:

UGameplayStatics::PlaySoundAttached(DamageType->DamageSound, FirstPersonCameraComponent,NAME_None,FVector(5,0,0));

the newer one that gives compile error:

UGameplayStatics::SpawnSoundAttached(DamageType->DamageSound, FirstPersonCameraComponent, NAME_None, FVector(5,0,0));

compile error:

error C2668: 'UGameplayStatics::SpawnSoundAttached': ambiguous call to overloaded function
    note: could be 'UAudioComponent *UGameplayStatics::SpawnSoundAttached(USoundBase *,USceneComponent *,FName,FVector,EAttachLocation::Type,bool,float,float,float,USoundAttenuation *,USoundConcurrency *)'
    or       
    'UAudioComponent *UGameplayStatics::SpawnSoundAttached(USoundBase *,USceneComponent *,FName,FVector,FRotator,EAttachLocation::Type,bool,float,float,float,USoundAttenuation *,USoundConcurrency *)'
        CompilerResultsLog:Error: Error x : note: while trying to match the argument list '(USoundCue *, UCameraComponent *, EName, FVector)'

the vector offset is important but gives compile error, all other arguments are unneeded for me.

I have the same problem and i fix it by include “Sound/SoundCue.h”.

For me it looks like the compiler can’t say which of those functions you want to use. So you need to do a clariication there for example:

UGameplayStatics::SpawnSoundAttached(DamageType->DamageSound, FirstPersonCameraComponent, NAME_None, FVector(5,0,0),EAttachLocation::KeepRelativeOffset );

When you do that, it should compile perfectly fine!

1 Like