Sound not being replicated


i hve a function for the fire action and when I press left click it triggers the function but I can hear the sound on the server and not the client idk why
Any help would be appreciated

To have the sound play on all other players PC’s in the vicinity you need to make you sound effect function a NetMulticast

Example
in the header the function definition would be

UFUNCTION(NetMulticast, Unreliable)
void MC_FireFX();

And in the cpp file you have the implementation

void YourClass::MC_FireFX_Implementation(){
  UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation())
}

Then in your fire function on the server after spawning your projectile call

if(Firesound != nullptr){
MC_FireFX(); 
}

p.s.
I set it to unrealiable because it’s usually a non critical effect. If it’s a stealth game then maybe make it releiable

1 Like

that didnt really work or maybe i did soemthing wrong
void APlayerCharacter::OnFire_Implementation()
{
if (IsShooting)
{
if(Projectile != NULL)
{
if(World != NULL)
{
if(Bullets != 0 && ReloadingGun == false && HealingPlayer == false && CanShoot == true)
{
SpawnRotation = GetControlRotation();

				SpawnLocation = ((MuzzleLocation != nullptr) ?
					MuzzleLocation->GetComponentLocation() :
					GetActorLocation()) + SpawnRotation.RotateVector((GunOffset));
				
				Bullets -= 1;
				IsShooting = true;
				FActorSpawnParameters ActorSpawnParams;
				ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AdjustIfPossibleButDontSpawnIfColliding;
				World->SpawnActor<AProjectile>(Projectile, SpawnLocation, SpawnRotation, ActorSpawnParams);
				UGameplayStatics::PlaySoundAtLocation(this, FireSound, GetActorLocation());
        
				if(FireSound != nullptr){
					OnFire();
				}
        
				if(FireAnimation != NULL && AnimInstance != NULL)
				{
					UAnimInstance* AnimInstance1P = HandsMesh->GetAnimInstance();
					if(AnimInstance1P != NULL)
					{
						AnimInstance1P->Montage_Play(FireAnimation, 1.0f);
					}

					//UAnimInstance* AnimInstance3P = Mesh3P->GetAnimInstance();
					//if(AnimInstance3P != NULL)
					//{
					//AnimInstance3P->Montage_Play(FireAnimation3P, 1.0f);
					//}
				}
				if(CurrentWeapon->GetWeaponID() == 1)
				{
					World->GetTimerManager().SetTimer(FireTimerHandle, this, &APlayerCharacter::OnFire, CurrentWeapon->FireRate, false);
				}
				else
				{
					IsShooting = false;
					FireTimerHandle.Invalidate();
				}
				
				World->GetTimerManager().SetTimer(FireTimerHandle, this, &APlayerCharacter::OnFire, CurrentWeapon->FireRate, false);
			}
		}
	}
}

}
image

The netmulticast function is only supposed play the sound and maybe add muzzle flash. The rest of the logic should be on a normal server function.

2 Likes

ohhh got it
let me try it

that worked thank you so much