HitTesting on server followed by SpawnEmitter on each client

I just started using Networking in Unreal for the first time and have a hard time figuring out how to Spawn my beam Effect so every client can see it.

void Fire();

UFUNCTION(Server, Reliable, WithValidation)
	void ServerFire();
	void ServerFire_Implementation();
	bool ServerFire_Validate();

UFUNCTION()
	void OnRep_PlayBeamChanged();

UPROPERTY(ReplicatedUsing = OnRep_PlayBeamChanged)
	bool bPlayBeamEffect;

my cpp code looks like this

void AInstantHitWeapon::Fire(){
	//HitTestCode
        bPlayBeamEffect = true;
        OnRep_PlayBeamChanged(); //I saw a post saying that in c++ you need to call it, as it only calls automatically in Blueprint.
        if (Role < ROLE_Authority){
	  	ServerFire();
	}
}
void AInstantHitWeapon::ServerFire_Implementation(){
	FireWeapon();
}
bool AInstantHitWeapon::ServerFire_Validate(){
	return true;
}
void AInstantHitWeapon::OnRep_PlayBeamChanged() {
	//Emit beam effect. Only show on the client calling Fire();
}

Can someone explain me what i am doing wrong ? Thanks!

That is only calling the function on the local client that fired the weapon. You need another function to do it. Add another UFunction set to be called on the client (ClientPlayBeam() for instance). Then in the ServerFire() call that function for each client you want it replicated to (non-owning clients).

call that function for each client you want it replicated to (non-owning clients)

How do I achieve that? Is there a way to get all the clients and iterate through? Or is it something else?
Just making a client function and calling it from server didn’t help.
NetMulticast didn’t work either

I wanted to pull an example up but I don’t have the ShooterGame sample on my machine. Download that and take a look at how the replicate fire effects. Typically, that’s not done on the weapon, but the controller. Anyway there should be a good example in ShooterGame

I copied the whole code of the ShooterGame AShooterWeapon_Instant class, and i have the same result as with my code. It only shows the trail on the client that fired it. Could it be my Weapon Spawning code? Or Project settings ?

Edit: Actually when i deactivate dedicated server, the player who host the game can fire and it shows on other clients. Other clients don’t.

Edit: Debugging shows that ServerNotifyHit(…) is called when i fire, but ServerNotifyHit_Implementation(…) is not being run through.

Have you defined the GetLifetimeReplicatedProps function?
For your code to work it should look like this (don’t forget to include UnrealNetwork.h):

void AClass::GetLifetimeReplicatedProps(TArray<FLifetimeProperty> & OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);

	DOREPLIFETIME_CONDITION(AClass, bPlayBeamEffect, COND_SkipOwner);
}

I found the solution. The Weapon Actor was fine all along. The problem is spawning this Actor and setting its owner for replication as its spawned by an other replicated actor.

Here is how to Spawn an Actor inside an other one:

	UPROPERTY(Replicated)
	AActor* weapon;

    void EquipWeapon();
	UFUNCTION(Server, Reliable, WithValidation)
	void ServerEquipWeapon();
	void ServerEquipWeapon_Implementation();
	bool ServerEquipWeapon_Validate();

cpp code:

void APlayerCharacter::EquipWeapon() {
	if (Role < ROLE_Authority){
		ServerEquipWeapon();
	}
	else{
		weapon = GetWorld()->SpawnActor<AInstantHitWeapon>(GetActorLocation(), FRotator::ZeroRotator);
		Cast<AInstantHitWeapon>(weapon)->OwningCharacter = this;
		weapon->SetOwner(this);
		weapon ->bReplicates = true;
	}
}
void APlayerCharacter::ServerEquipWeapon_Implementation() {
	EquipWeapon();
}
bool APlayerCharacter::ServerEquipWeapon_Validate() {
	return true;
}

void APlayerCharacter::BeginPlay()
{
	Super::BeginPlay();
	
	EquipWeapon();
}