[SOLVED] Client not dealing damage to server

I have a Blueprint setup that is not dealing damage to the player when client is shooting the server. Obviously…Server can deal damage to client. What i have right now is Character Blueprint that calls a Run On Server Event on my Weapon_Master class. That event calls another event which does a line trace to check for player and deal damage. Here is the setup:

Character Blueprint:

Weapon_Master Blueprint (Handle Firing function updates the ammo count and calls Fire Weapon event):

Weapon_Master (Fire Weapon event). Both Client and Server shows the Weapon Fired log:

I also tried creating a custom event in Character Blueprint called TakeDamage and calling it from Weapon_Master Blueprint but still no luck. The Apply Damage Breakpoint triggers from client but Event Any Damage never triggers from client. :frowning:


I think your “Weapon_Master (Fire Weapon event)” should be run on the server only - the client cannot be trusted to perform hit calculations. I would also just call the “Apply Damage” function if a target is hit rather than just subtracting from health.

Done that. Still no luck. :frowning:

Thats what i am doing actually (see the last pic). I just tried subtracting health to see if it works. But unfortunately its not working.

Does it work when running on the server and not when running from client? Make sure you set the actors to replicate.

Put in print string a few places to see where the different things are running it will save server: hello or what ever. So you know if what you are doing is running on client or server.

Both actors (character and weapon_master) are set to replicate. There is a Debug Log (which prints to screen) in Fire Weapon event and it does appear for client. If you look at the last screenshot you can see i set a Breakpoint for ApplyDamage() and it triggers for client. But Event Any Damage never gets fired and any breakpoint in that event is ignored.

You have roughly the right ideas, input event on the client sends a Server RPC to actually do the firing (perhaps with who the client thinks he hit and server can either trust him or do his own verify). It looks like you have the part right, but something is getting absorbed along the way and never calling the actual do damage logic.

ApplyDamage is being called, but the AnyDamage event never triggers:
-The blueprint is definitely executing on the server for the client who is shooting, correct? Both ApplyDamage and AnyDamage events are Authority Only so they will never run on clients (they can run for clients on server, but they dont run on the client ever).
-If this is running on the server, the best advice is to look at UGameplayStatics::ApplyDamage and step through. Perhaps damage applied ends up being 0 for some reason.

Hi Ratti. I still cant figure out whats wrong with this system. I tried everything from setting all events to Multicast/Run On Server etc but still no luck. No matter what i do i cant figure out whats wrong.

I changed the FireWeapon event like this now so TakeDamage event will be called.

And see this. You can see the TakeDamage event is called with proper damage value. But still…server doesnt get any damage.

If i send you the project (via PM), could you please take a look and see whats wrong?

EDIT: I’ve posted this on Answerhub](Client not dealing damage to server - Programming & Scripting - Epic Developer Community Forums) too.

The built-in “Any Damage” event is authority only, so it will never run on the client. This is OK though, generally the server should be the only one that actually applies damage to characters, and the clients can find out about the health change if the health value is replicated. If you’d like clients to react to the health change, perhaps to play an animation or sound, one option is to set the health variable’s replication to RepNotify. This will create a corresponding On Rep function that will be called automatically when the server changes the value.

Hi Ryan,

As you said the Any Damage is authority function only. So shouldn’t this workflow work:

1: Client shoots and hits character (Server)
2: Calls TakeDamage (Run On Server) event
3: Executes Any Damage Event

Yes, that should work. However if the “Base damage” value passed in to Apply Damage is 0, Any Damage will be skipped. Also double check that “Can be damaged” is set to true for your character.

Sounds like a similar problem I had last week. I ended up solving it by setting the Owner.

The Server replicated event only executes on the server if the client that calls the function is the Owner. In my case, the weapon owner was NULL (I spawned the weapon in my pawn’s Begin Play event) and thus the event never executed on the server.
To solve this I had to wrap the SetOwner() function in a blueprint callable function as the SetOwner() function is not exposed to blueprints… But even before that, I would expect SpawnActor to set the value of Owner to the same value as Instigator tbh. Or at least supply an optional Owner parameter.

Well it doesnt work unfortunately. As i showed in the picture “Base Damage” value is not 0 (I’ve even set the variable to replicated) and made sure with print strings the value is not 0 and its not. I am sure its something bad on my side but still cant figure out why. :frowning:

Hi Omar007. As you said i tried setting SetOwner for client but then Run On Server events never fire from Clients. Can you show me whats your setup on your side?


I wrapped it in a function to keep my Event Graph clean and I just call that function from Begin Play.

In this function check if I’m the server and if I am, I spawn the weapon actor (this actor replicates) and store it in the character’s Weapon variable (variable replicates).
I then set the owner of the weapon to the character (as I call the weapon’s firing/reload functions from my character). Lastly I attach it to the weapon attachment point.

Ofcourse the weapon fire and reload functions are ‘Run on Server’.

In my case, I would be unable to fire if I did not include my custom SetOwnerTo node.

FYI, from the Run on Server weapon fire function you could call a Multicast function as well for firing effects that you may want to play on all clients.
That is what I do but the actual firing logic is not really relevant for this problem I guess :stuck_out_tongue:

Thank you very much for the help Omar007! Finally with your help, client now deals damage to server. Although i do now have weapon position issue in First Person i’ll make another thread on Answerhub for that. :slight_smile:

For future users here is the C++ code i used. Since I already had a custom C++ Blueprint Function Library all i had to do was add this new node into that. But for new users you can follow this tutorial on how to add custom Blueprint node.

Header file:

UFUNCTION(BlueprintCallable, Category = "MyCustomCategory")
static void SetNewOwner(AActor* NewOwner, AActor* Weapon);

Source file:

void USplashivBPLibrary::SetNewOwner(AActor* NewOwner, AActor* Weapon) 
     if (!NewOwner == NULL && !Weapon == NULL)

I know its a old post but I have the same problem… Clients cant damage server. I wanna know how you get through this issue… I created a new blueprint library and added your code then set the owner after spawned the weapon… but still cant get damage to server… What am I missing?

Is the issue that the projectiles no longer come out of the right socket? Because I have that exact same problem now. The source of this problem comes from the fire on server. If it doesnt fire on server, the server wont take damage. If it does fire on server, it wont shoot correctly. How did you fix this? Please help me.