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);
}
}
}
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.
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.
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.