Hello, I have finished the [multiplayer quick start tutorial][1] just now. But I am confused because the OnHealthUpdate() method doesn’t work as it suppose to work.
I extended the behavior of the ThirdPerson character as per the tutorial says. It has a method called OnHealthUpdate(). When CurrentHealth variable is updated, this method is called as to notify the whole actor. According to the method’s logic, it should print a different text on the screen depending on whether the game is client or server.
void AThirdPersonMPCharacter::OnHealthUpdate()
{
const float MessageDuration = 60.0f;
// Client specific functionality
if (IsLocallyControlled()) {
FString healthMessage = FString::Printf(TEXT("You now have %f health remaining."), CurrentHealth);
GEngine->AddOnScreenDebugMessage(-1, MessageDuration, FColor::Green, healthMessage);
if (CurrentHealth <= 0)
{
FString deathMessage = FString::Printf(TEXT("You have been killed."));
GEngine->AddOnScreenDebugMessage(-1, MessageDuration, FColor::Red, deathMessage);
}
}
// Server specific functionality
if (GetLocalRole() == ROLE_Authority) {
FString healthMessage = FString::Printf(TEXT("%s now has %f health remaining."), *GetFName().ToString(), CurrentHealth);
GEngine->AddOnScreenDebugMessage(-1, MessageDuration, FColor::Green, healthMessage);
}
}
However, when I test the game, this logic doesn’t execute correctly. I ran the game in the editor with 2 players and one being as listening server and other is client. I can see the both messages in both client and server. Could someone explain me this? Should I see client-specific message in client and server-specific message in server?