Is this correct and why doesn't it work if so

Hoy,

I have this function being called on a pawn.
If it’s the server/host i get the log “SV Playing Sound” and if it’s a client I get the log “CL Playing Sound”

but the sound never plays.

If i remove

if (IsLocallyControlled())

it plays but it plays twice. It’s only meant to play for the local player.

void ACWPawn::PlayFlybySound_Implementation()
{
    if (IsLocallyControlled())
    {
        if (flybySound)
        {
            if (HasAuthority())
            {
                UE_LOG(LogTemp, Error, TEXT("SV Playing Sound "));
            }
            else
            {
                UE_LOG(LogTemp, Error, TEXT("CL Playing Sound "));
            }

            UGameplayStatics::PlaySoundAtLocation(GetWorld(), flybySound, GetActorLocation(), 1.0f, 1.0f, 0.0f, nullptr);

        }
    }
}

in both server and client mode, it’s not playing?

Nope, it doesn’t play for either the server or the client. I get the logs properly but no sound.
the function is declared like so

	UFUNCTION(Client,Reliable)
	void PlayFlybySound();

If it helps…

I’m telling the server to spawn an actor in a multicast function, and when I overlap that actor thats when the OnFlybySphereOverlapped function is called.

If it’s an actor placed in the editor it all works fine but if it’s an actor spawned by the server during play it’s when it fails. I didn’t think that’d make a difference considering the logs get shown as expected.

When OnFlybySphereOverlapped is called I tell the client to update a progress bar in their HUD, and it updates as expected.

Turn off run under one process

You should get the sound.

You can also run it in standalone game mode.

You will only get one firing from the client though. So you won’t get both to client and server to trigger as you limited in the UFUNCTION to be client only.

You can change the code to

.h

UFUNCTION(BlueprintCallable)
void PlayFlybySound();

cpp


void ACWPawn::PlayFlybySound()
{
   
        if (flybySound)
        {

            if (IsLocallyControlled())
            {
                if (HasAuthority())
                {
                    UE_LOG(LogTemp, Error, TEXT("SV Playing Sound "));
                    GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Red, TEXT("SV Playing Sound "));
                }
                else
                {
                    UE_LOG(LogTemp, Error, TEXT("CL Playing Sound "));
                    GEngine->AddOnScreenDebugMessage(-1, 10, FColor::Orange, TEXT("CL Playing Sound "));
                }
                UGameplayStatics::PlaySoundAtLocation(GetWorld(), flybySound, GetActorLocation(), 1.0f, 1.0f, 0.0f, nullptr);
        }

    }
}

That way you can see the messages on screen.

But if you are using beginplay to trigger it then it will still only be called on the server as that is where the the pawns will all be spawned. So the function call time and caller is more important in this case.

Interesting!

this option lets the server play the sound in PIE but not for the client, playing in standalone works as expected though.

Thanks for the help :slight_smile:

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