Hey all.
Got a question I wanted to pose regarding replicating an effect in a network game, because I’m seeing some weirdness.
So I’ve got a suppression value per character that is meant to represent how much fire they have been under and it does various visual changes.
Anyway, I’ve got it mostly working, but for the life of me there is a case where it doesn’t make any sense. So wanted to run it past you guys.
So the variable itself is a float, it is set to replicate as such:
UPROPERTY(BlueprintReadOnly,Transient, ReplicatedUsing = OnRep_Suppression, Category = Health)
float Suppression = 0;
Now I’ve got a few methods:
void AShooterCharacter::OnRep_Suppression_Implementation()
{
//UE_LOG(LogShooter, Warning, TEXT("Help help I'm being supressed!"));
UE_LOG(LogShooter, Warning, TEXT("Client replication recieved notify to surpress %s is now %f"), *GetDebugName(this), Suppression);
}
void AShooterCharacter::Suppress(FHitResult hit, FVector start, FVector end)
{
if (Role < ROLE_Authority)
{
UE_LOG(LogShooter, Warning, TEXT("Client being asked to surpress %s is currently %f"), *GetDebugName(this), Suppression);
ServerSuppress(hit,start,end);
}
else
{
Suppression += SuppressionScale;
UE_LOG(LogShooter, Warning, TEXT("Server sees Suppression for Actor %s is now %f"), *GetDebugName(this), Suppression);
}
}
bool AShooterCharacter::ServerSuppress_Validate(FHitResult hit, FVector start, FVector end)
{
return true;
}
void AShooterCharacter::ServerSuppress_Implementation(FHitResult hit, FVector start, FVector end)
{
UE_LOG(LogShooter, Warning, TEXT("Server implementing suppression calling supress function for %s"), *GetDebugName(this));
Suppress(hit,start,end);
}
As you can probably see. I’m using a pattern similar to what I’ve seen in other replication code. I call the Suppress method on the character that has been fired at (I use a overlap sphere check for the firing and that works). It then checks if this is the AUTHORITY (i.e. server) and if it isn’t it calls ServerSuppress, which in turn should call the ServerSuppress_Implementation method on the server. Only this is where weird things happen. On a dedicated server, it all works as intended. When one of the connections is a local server, things tend to go wrong. The server player can suppress the other client. But the other client can only suppress the server if during its firing, the line trace hits another surface nearby the player.
I suspect what is happening is that the suppression method via the RPC to the server is only getting sent when another packet is being sent to the server. Otherwise I see no printed values from my debug log. So basically it stays at the client end entirely.
Anyone spot any obvious flaws in my thinking?