Announcement

Collapse
No announcement yet.

[SOLVED] Client not dealing damage to server

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [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.
    Last edited by ryanjon2040; 11-27-2014, 02:37 AM. Reason: Big Thanks to Omar007! See post #14
    Support my RTS Game (Agora) on Patreon!
    Unreal Nexus - Create Share and Experience!
    Unreal Engine 4 World-Wide User Map

    [PLUGIN] Aws Gamelift Client Plugin
    [TOOL] Create your own binary release of UE4 from GitHub source
    My UE4 Tutorials and Misc Tools

    Lead Programmer at YetiTech Studios
    Your Friendly Neighborhood
    Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

    #3
    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.

    Comment


      #4
      Originally posted by Chumble View Post
      I think your "Weapon_Master (Fire Weapon event)" should be run on the server only - the client cannot be trusted to perform hit calculations.
      Done that. Still no luck.

      Originally posted by Chumble View Post
      I would also just call the "Apply Damage" function if a target is hit rather than just subtracting from health.
      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.
      Support my RTS Game (Agora) on Patreon!
      Unreal Nexus - Create Share and Experience!
      Unreal Engine 4 World-Wide User Map

      [PLUGIN] Aws Gamelift Client Plugin
      [TOOL] Create your own binary release of UE4 from GitHub source
      My UE4 Tutorials and Misc Tools

      Lead Programmer at YetiTech Studios
      Your Friendly Neighborhood
      Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

      Comment


        #5
        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.

        Comment


          #6
          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.
          Support my RTS Game (Agora) on Patreon!
          Unreal Nexus - Create Share and Experience!
          Unreal Engine 4 World-Wide User Map

          [PLUGIN] Aws Gamelift Client Plugin
          [TOOL] Create your own binary release of UE4 from GitHub source
          My UE4 Tutorials and Misc Tools

          Lead Programmer at YetiTech Studios
          Your Friendly Neighborhood
          Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

          Comment


            #7
            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.

            Comment


              #8
              Hi Dave 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 too.
              Last edited by ryanjon2040; 11-13-2014, 05:57 AM. Reason: Added answerhub link
              Support my RTS Game (Agora) on Patreon!
              Unreal Nexus - Create Share and Experience!
              Unreal Engine 4 World-Wide User Map

              [PLUGIN] Aws Gamelift Client Plugin
              [TOOL] Create your own binary release of UE4 from GitHub source
              My UE4 Tutorials and Misc Tools

              Lead Programmer at YetiTech Studios
              Your Friendly Neighborhood
              Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

              Comment


                #9
                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.

                Comment


                  #10
                  Originally posted by Ryan Gerleve View Post
                  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
                  Support my RTS Game (Agora) on Patreon!
                  Unreal Nexus - Create Share and Experience!
                  Unreal Engine 4 World-Wide User Map

                  [PLUGIN] Aws Gamelift Client Plugin
                  [TOOL] Create your own binary release of UE4 from GitHub source
                  My UE4 Tutorials and Misc Tools

                  Lead Programmer at YetiTech Studios
                  Your Friendly Neighborhood
                  Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

                  Comment


                    #11
                    Originally posted by ryanjon2040 View Post
                    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.

                    Comment


                      #12
                      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.
                      Last edited by Omar007; 11-21-2014, 08:48 AM.

                      Comment


                        #13
                        Originally posted by Ryan Gerleve View Post
                        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.
                        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.

                        Originally posted by Omar007 View Post
                        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.
                        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?
                        Support my RTS Game (Agora) on Patreon!
                        Unreal Nexus - Create Share and Experience!
                        Unreal Engine 4 World-Wide User Map

                        [PLUGIN] Aws Gamelift Client Plugin
                        [TOOL] Create your own binary release of UE4 from GitHub source
                        My UE4 Tutorials and Misc Tools

                        Lead Programmer at YetiTech Studios
                        Your Friendly Neighborhood
                        Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

                        Comment


                          #14
                          Sure.

                          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 :P
                          Last edited by Omar007; 11-22-2014, 12:56 PM.

                          Comment


                            #15
                            Originally posted by Omar007 View Post
                            Sure.

                            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 :P
                            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.
                            Support my RTS Game (Agora) on Patreon!
                            Unreal Nexus - Create Share and Experience!
                            Unreal Engine 4 World-Wide User Map

                            [PLUGIN] Aws Gamelift Client Plugin
                            [TOOL] Create your own binary release of UE4 from GitHub source
                            My UE4 Tutorials and Misc Tools

                            Lead Programmer at YetiTech Studios
                            Your Friendly Neighborhood
                            Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

                            Comment

                            Working...
                            X