Hello all,
I have a projectile that a player shoots, then on impact with another player it plays a “hit” sound.
The Pawn class calls a Server RPC HandleFire that spawns the projectile.
void ATechnomancyCharacter::HandleFire_Implementation()
{
...
GetWorld()->SpawnActor<ABaseAttack>(SpawnLocation, Direction.Rotation(), SpawnParameters);
...
}
Then the OnProjectileOverlap function of the projectile calls a Client RPC called PlayClientSound
void ABaseAttack::OnProjectileOverlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
...
IGameObject* OtherObject = Cast<IGameObject>(OtherActor);
IGameObject* InstigatorObject = Cast<IGameObject>(Instigator);
...
if (OtherObject && InstigatorObject)
{
...
InstigatorObject->PlayClientSound(HitSound);
}
...
}
Here is the Client RPC
void ATechnomancyCharacter::PlayClientSound_Implementation(USoundCue* Sound)
{
UGameplayStatics::PlaySound2D(GetWorld(), Sound);
}
So in a multiplayer setting (listen server) I get some strange replication issues. When I play as a client things work as intended (meaning when I hit another player I get the “Hit” sound), but when I play as the server I will get the sound but it will SOMETIMES also play the sound on the client which is obviously not wanted.
Is there something I am doing wrong with the RPC calls I am making to cause this?