Hello. I am new to multiplayer developing and I have a problem with Client. I can’t say to Server that I want to decrease my health. If I’m a host then all works fine, but when I’m a client I get the warning:
.h
UFUNCTION()
void TakeDamage(float damage) override;
UFUNCTION(Server, Reliable, WithValidation)
void Server_TakeDamage(float damage);
UFUNCTION()
void DecreaseHealth(float decrement);
.cpp
void ACustomCharacter::TakeDamage(float damage)
{
if (Role < ROLE_Authority)
{
//Client can't call the function
Server_TakeDamage(damage);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Client takeDamage"));
} else
{
//Server works properly
DecreaseHealth(damage);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Server takeDamage"));
}
}
void ACustomCharacter::Server_TakeDamage_Implementation(float damage)
{
DecreaseHealth(damage);
}
bool ACustomCharacter::Server_TakeDamage_Validate(float damage)
{
return true;
}
void ACustomCharacter::DecreaseHealth(float decrement)
{
health -= decrement;
}
What am I doing wrong? Please, help!