Attenuation Settings parameter problem in BeginPlay() (SpawnSoundAtLocation) C++

The SpawnSoundAtLocation() function returns a null pointer when executed in BeginPlay().
But if I execute it outside of BeginPlay() it works perfect (return a valid pointer).

Is there any other overridable function suitable for spawning audio?


The problem is caused by the “Attenuation Settings” parameter.

	Audio = UGameplayStatics::SpawnSoundAtLocation
	(
		World,
		Sound, 
		Location,
		Rotation, 
		Volume, 
		PitchMultiplier, 
		StartTime, 
		nullptr,           //AttenuationSettings, 
		nullptr,           //ConcurrencySettings,
		false              //AutoDestroy
	);

if AttenuationSettings=nullptr; then it works in BeginPlay() (Audio is a valid pointer)

if AttenuationSettings parameter is got like this:

UPROPERTY(EditDefaultsOnly)
class USoundAttenuation *AttenuationSettings = nullptr;|

Or like this:

UPROPERTY(EditDefaultsOnly)
TObjectPtr<class USoundAttenuation> AttenuationSettings = nullptr;

Then it does not works in BeginPlay() (Audio is not a valid pointer)

The AttenuationSettings file appears to be fine (doesn’t look to be corrupt).

So it’s a big problem for me… I need the attenuation. And I need to spawn the audio as soon as possible like in BeginPlay().

Any help to solve this problem is welcome.


Thank you so much!!

I think I have found an alternative solution:

This works in BeguinPlay()


	Audio = UGameplayStatics::SpawnSoundAtLocation
	(
		World,
		Sound, 
		Location,
		Rotation, 
		Volume, 
		PitchMultiplier, 
		StartTime, 
		nullptr,           
		nullptr,           
		false              
	);

Then apply the attenuation when I need to play.

Audio->AdjustAttenuation(AttenuationSettings->Attenuation);
Audio->Play();

But I have not been able to verify if it really works because "au.Debug.SoloAudio" is not working either.


Ok I think it works (finally)…

I Hate The Software Development Life Cycle… Especially when instead of fixing things they break them.