Audio que is not playing on Preview Client, but is on Preview Server

Ive been working from the tutorial A new, community-hosted Unreal Engine Wiki - Announcements - Unreal Engine Forums.

In there, there is a UsableItem > PickupItem > ConsumableItem.

The “PickupItem” class has logic to play a sound que at location which works like so:

UGameplayStatics::PlaySoundAtLocation(this, PickupSound, GetActorLocation());

It works, but when I have multiplayer viewports open I notice the sound only plays on the “Preview Server” viewport, It does not play the sound inside the “Preview Client”. I can also pick up the item with the Client player but I can only hear the sound playing in the “Preview Server” viewport.

As a workaround Ive tried placing the, “PickupSound” sound que inside an AudioComponent. I Initialize the AudioComponent, and tried to replace the “PlaySoundAtLocation” in the OnUsed function like so:

    //UGameplayStatics::PlaySoundAtLocation(this, PickupSound, GetActorLocation());
    if (PickupSound)
    	{
    		AudioComp->SetSound(PickupSound);
    		AudioComp->Play();
    	}

But this is even worse, as nothing plays when trying to activate the sound this way, not in Client nor Server viewports.

For settings Ive checked the box in Editor Preferences > Play > Create Audio Device for Every Player

Im not sure what to do next aside from rebuilding everything over again, but I cannot see anything in the code that I would do differently especially in those few files that create the item.

Anyone have an idea of what might be going on and what I can do?

Hey, so how are you calling PlaySoundAtLocation? From C++? I recommend calling the function from blueprints – I just ran a test with a simple setup in the level blueprint as follows:

The sound played properly in all the multiple PIE sessions I launched (PIE => play in editor) which simulates the multiple clients. The thing that is tricky is the static function in C++ actually takes a WorldContextObject as its first argument:

void UGameplayStatics::PlaySoundAtLocation(UObject* WorldContextObject, class USoundBase* Sound, FVector Location, FRotator Rotation, float VolumeMultiplier, float PitchMultiplier, float StartTime, class USoundAttenuation* AttenuationSettings)

In blueprints, this is automatically passed to the blueprint function and will play the sound in the appropriate viewport/world (and thus be heard across the multiple PIE sessions). If you call the function manually in C++, you need to make sure you pass in the appropriate WorldContextObject. My guess is that the “this” pointer in your code is the world context for only one of the PIE viewports. I looked through the tutorial briefly and didn’t see how they’re setting up the call from C++ and what “this” is.

Another thing that could be happening is that the “multiple audio device” feature automatically mutes the PIE windows that aren’t in-focus (i.e. the currently controlled PIE viewport). As you flip between the viewports, it will play audio from that viewport (and mute the old viewports). The idea is that you really only want to hear one audio viewport at a time (otherwise it’d be cacophony). You can bypass this by specifically soloing one viewport so you can hear audio from that viewport while you control another.

[quote=“Aaron McLeran, post:2, topic:326985, username:Minus_Kelvin”]You can bypass this by specifically soloing one viewport so you can hear audio from that viewport while you control another.
[/quote]
I have the same problem, and I would like to try this. But how exactly do you do this?