Playing announcer sound in UE4

Hello,

I’m trying to figure how to play an announcer sounds in UE4. This means it’s a non-positional, “fire and forget” sound.

I’m not sure which function to call (since all of them seem to rely on position data), and not sure how to make it global. I couldn’t find any NetMulticast functions on AGameMode, and I’m a bit confused where this should go.

Can you give me some advice here?

Thanks in advance! :slight_smile:

Use UGameplayStatics::PlaySoundAttached function, attach the sound to the player and specify location as FVector::ZeroVector. That should help you achieve the effect you want.

More info about PlaySoundAttached function: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Kismet/UGameplayStatics/PlaySoundAttached/index.html

Thank you Ogniok!
Do you recommend a way to make a template function for that? Or place it somewhere, where all connected players will get that call? :slight_smile:
I assume that would require a NetMulticast function, but I’m not sure where to call it :frowning:

Make a function(in example inside your GameMode) that will be replicated to all clients and call PlaySoundAttached inside. You can obtain a player actor reference from world context(GetWorld()->GetFirstPlayerController()->GetPawn()).

To learn more about networking in C++ I recommend looking at ShooterGame project. :slight_smile:

Actually, I’m good with C++, I moved from the Source Engine to UE4. I was looking for the recommended or the best way of doing this.
Still, thank you! I thought the GameMode class shouldn’t use replicated/netmulticast functions, but apparently it can. I’ll give it a try tomorrow :slight_smile:

If anyone ever stumbles upon this, this is how I done it:

void AMyGameMode::PlayAnnouncerSound(class USoundBase* Sound)
{
	for (FConstPlayerControllerIterator Iterator = GetWorld()->GetPlayerControllerIterator(); Iterator; ++Iterator)
	{
		if (!(Iterator->IsValid())) continue;

		Iterator->Get()->ClientPlaySound(Sound);
	}
}

Enjoy :slight_smile:

Very nice. Thanks for sharing! :smiley: