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.
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: