I’m trying to make a damage flicker effect, achieved through a dynamic material, for when my enemies get hit in my multiplayer game.
This is how I’m calling the function:
void AEnemy::OnRep_Damaged() {
PlayDamageFlash();
}
and this is how I currently have the network functions set up.
void AEnemy::PlayDamageFlash() {
if (Role < ROLE_Authority) {
//DynamicEnemyMaterial->SetScalarParameterValue(FName("StartTime"), World->GetTimeSeconds()); // <== calling it as client will cause a fatal error
ServerPlayDamageFlash();
}
else {
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT(" PlayDamageFlash Called on Server =: %s"), Role == ROLE_Authority ? TEXT("True") : TEXT("False")));
DynamicEnemyMaterial->SetScalarParameterValue(FName("StartTime"), World->GetTimeSeconds());
}
}
void AEnemy::ServerPlayDamageFlash_Implementation() {
PlayDamageFlash();
}
bool AEnemy::ServerPlayDamageFlash_Validate() {
return true;
}
Unfortunately, with the current set up only the server’s material flashes, but if I try to get the client’s to flash, then I’m getting an access violation on the client’s side.
I know it can work, as if I change the material scaler in the tick function, then both work.
It seems to be that the server is looking in the wrong place on the client for the location of the material using an incorrect pointer address, perhaps?
I can think of a couple of workarounds, but I’m sure this should work, and I’m just doing something stupid.
Still looking at this, but if anyone can chip in, then I would be grateful!