# Why PlaySound2D does work when press a key but not when the event is triggered?

**URL:** <https://forums.unrealengine.com/t/why-playsound2d-does-work-when-press-a-key-but-not-when-the-event-is-triggered/1760323>\
**Category:** Getting Started & Setup\
**Tags:** Networking, hud, unreal-engine, Widget, Blueprint, question, CPP\
**Created:** [March 18, 2024, 12:35pm UTC](https://forums.unrealengine.com/t/why-playsound2d-does-work-when-press-a-key-but-not-when-the-event-is-triggered/1760323 "2024-03-18T12:35:21Z")\
**Posts on this page:** 5\
**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:** [March 18, 2024, 12:35pm UTC](https://forums.unrealengine.com/t/why-playsound2d-does-work-when-press-a-key-but-not-when-the-event-is-triggered/1760323/1 "2024-03-18T12:35:21Z")

</div>

This is the UI code:

 ![Captura de pantalla 2024-03-18 120725](https://d3kjluh73b9h9o.cloudfront.net/original/4X/1/d/3/1d30b443e9dbcf9e2dc8e5a1a6a4da2f7b624814.png)

PlaySound2D does work when a key is pressed but not when the event is triggered.

Enyone knows why?

The widget is a component of the HUD class.

This is how the event is triggered (for test purposes only):

.h

```auto

UPROPERTY(ReplicatedUsing=NotifyToClientEvent)
bool bHealth=false;
UFUNCTION()
void NotifyToClientEvent();

```

.cpp

```auto
//-----------------------------------------------------------------------------
void UHealthComponent::NotifyToClientEvent()
{
	if (OnHealthChangeClientEvent.IsBound())	
		OnHealthChangeClientEvent.Broadcast( GetHealthValue() );	
}
//-----------------------------------------------------------------------------
void UHealthComponent::OnTakeAnyDamage(
	AActor* DamagedActor, float Damage, const class UDamageType* DamageType,
	class AController* InstigatedBy, AActor* DamageCauser)
{

	bHealth = !bHealth;
}
//-----------------------------------------------------------------------------

```

Any idea?  
Thank you so much!!

---

<div class="post-metadata">

**Author:** ![eldany.uy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/eldany.uy/32/821920_2.png) [@eldany.uy](https://forums.unrealengine.com/u/eldany.uy)\
**Post date:** [March 19, 2024, 10:26am UTC](https://forums.unrealengine.com/t/why-playsound2d-does-work-when-press-a-key-but-not-when-the-event-is-triggered/1760323/2 "2024-03-19T10:26:37Z")

</div>

you have an Is valid condition and 3 Ifs. have you tried to print something on false results and at the beginning of the event to find out where is failing?

---

<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:** [March 19, 2024, 11:00am UTC](https://forums.unrealengine.com/t/why-playsound2d-does-work-when-press-a-key-but-not-when-the-event-is-triggered/1760323/3 "2024-03-19T11:00:12Z")

</div>

Hi  
Yes, I have this checks… all they are valid in all cases

 ![Captura de pantalla 2024-03-19 104757](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/e/0/ce033bbcbf4420414714e112823c8767f69ea888.png)

I added this too (As you said)… but it seem the logic is fine. It does works… but no sound is played.

 ![Captura de pantalla 2024-03-19 105637](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/d/b/bdb00e0dfbd26cbf01c0ffe9dbc90c91c007db5f.png)

The event is executed in all cases too… It can be seen in visual debugger (in the video).

Thanks for your help

---

<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:** [March 21, 2024, 7:38am UTC](https://forums.unrealengine.com/t/why-playsound2d-does-work-when-press-a-key-but-not-when-the-event-is-triggered/1760323/5 "2024-03-21T07:38:02Z")

</div>

HI @eldany.uy

I think we fund the problem

> [@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

Unfortunately the solution seem to be bugged

> [@I think "Allow Background Audio" is not working](https://forums.unrealengine.com/t/i-think-allow-background-audio-is-not-working/1764161):
>
> I opened a thread on the forum because the audio doesn’t seem to work in a specific situation. You can see all details here: [https://forums.unrealengine.com/t/i-need-help-to-fix-an-audio-problem-userwidget/1762544?u=ivan3z](https://forums.unrealengine.com/t/i-need-help-to-fix-an-audio-problem-userwidget/1762544) A user gave me a solution: [https://forums.unrealengine.com/t/i-need-help-to-fix-an-audio-problem-userwidget/1762544/2?u=ivan3z](https://forums.unrealengine.com/t/i-need-help-to-fix-an-audio-problem-userwidget/1762544/2) ENABLE: “Level Editor/Miscellaneous/Allow Background Audio” But that option doesn’t seem to work (See Video Attached Here). [https://forums.un…](https://forums.unrealengine.com/t/i-need-help-to-fix-an-audio-problem-userwidget/1762544/3)

Anyway i want thank you for your help!! ❤

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [April 20, 2024, 7:38am UTC](https://forums.unrealengine.com/t/why-playsound2d-does-work-when-press-a-key-but-not-when-the-event-is-triggered/1760323/6 "2024-04-20T07:38:39Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
