0

MyCharacter.h

 UPROPERTY(Replicated, EditDefaultsOnly)
 float Health;

MyCharacter.cpp

 float AMyCharacter::TakeDamage(float Damage, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
 {
     Health -= Damage;
     return Damage;
 }

When i start my game and call TakeDamage from server, then It's working well. But if i call TakeDamage from client, it doesn't reflect Health at server. So i tried to make RPC function MulticastRPCTakeDamage(float Damage) and replace Health -= Damage.

 float AMyCharacter::TakeDamage(float Damage, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)
 {
     MulticastRPCTakeDamage(Damage);
     return Damage;
 }

I also tried ServerRPCTakeDamage and ClientRPCTakeDamage. But it's not working well. Help me!

김진우
  • 161
  • 3
  • 12
  • You probably want a to funnel health reduction through an on take hit server function (Not multicast or client). Leaving health replicated is fine. The problem with this approach is if other bits of the game are predicted, movement or dealing damage. The health reduction will have a delay of ping time on clients. This is usually solved in a very case by case way if at all. – George Jan 05 '21 at 12:29
  • @George So what can i do for dealing damage from client to server? The reason of this question is exactly about it. I'd uploaded the same question at AnswerHub. (link : https://answers.unrealengine.com/questions/1004473/view.html). But i don't understand that answer. So can you help me with example source code? – 김진우 Jan 08 '21 at 09:22

1 Answers1

0

Answer myself. Replicated variable is replicated value of server to client. So if you want to change value of the variable that has Replicated property from client and replicate to server, you have to use RPC. My mistake is, i made RPC function at the other Actor that non-playable. RPC is callable only the actor that player owns. So, what did i do for solve this problem?

  1. Make UFUNCTION(Server) function for notice what is client doing at player own actor (etc, AMyCharacter)
  2. Make UFUNCTION(NetMulticast) function doing actual action for all client and server.
  3. Call Server RPC function.
김진우
  • 161
  • 3
  • 12