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

**URL:** <https://forums.unrealengine.com/t/attenuation-settings-parameter-problem-in-beginplay-spawnsoundatlocation-c/2153241>\
**Category:** Audio\
**Tags:** unreal-engine, question\
**Created:** [November 26, 2024, 8:58pm UTC](https://forums.unrealengine.com/t/attenuation-settings-parameter-problem-in-beginplay-spawnsoundatlocation-c/2153241 "2024-11-26T20:58:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [November 26, 2024, 8:58pm UTC](https://forums.unrealengine.com/t/attenuation-settings-parameter-problem-in-beginplay-spawnsoundatlocation-c/2153241/1 "2024-11-26T20:58:02Z")

</div>

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.

```auto
	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:

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

```

Or like this:

```auto
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!!

---

<div class="post-metadata">

**Author:** ![Ivan3z](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ivan3z](https://forums.unrealengine.com/u/Ivan3z)\
**Post date:** [November 27, 2024, 6:07am UTC](https://forums.unrealengine.com/t/attenuation-settings-parameter-problem-in-beginplay-spawnsoundatlocation-c/2153241/4 "2024-11-27T06:07:49Z")

</div>

I think I have found an alternative solution:

This works in BeguinPlay()

```auto

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

```

Then apply the attenuation when I need to play.

```auto
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.

> [@I need help to fix an audio problem (UserWidget)](https://forums.unrealengine.com/t/i-need-help-to-fix-an-audio-problem-userwidget/1762544/2):
>
> Can you try to set “AllowBackgroundAudio” to true in the editor settings? It is disabled by default - and I think that is why you are not hearing any sound (because the second PIE window has no user focus and thus is in the background) [image] Let me know if this fixes it +1

* * *

Ok I think it works (finally)…

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

* * *
