No announcement yet.

Replication trouble

  • Filter
  • Time
  • Show
Clear All
new posts

    Replication trouble

    Hi there! For a week now I have this interesting problem with which I cannot really wrap my head around it. I'm trying to replicate a few events from owning client to all clients. Unfortunately for some reason my general approach (run on server if owning client -> has authority -> multicast) isn't working and not even the run on server get's called even though the actor is replicated and always relevant.

    To be more specific, I have a weapon placed in the scene that can be picked up so far so good but when I try to fire it, client is unable to call server events eg. spawn muzzle effect, run line trace, etc. Unlike server which can do everything as it should.

    Any suggestion would be greatly appreciated, thanks in advance,

    I need a little more information about your setup. Are you running the server as a listen server (Client 1 is effectively the server with "authority" and Clients 2+ are connecting to Client 1) or a dedicated server (Server is launched separately from the clients, Clients 1+ are all "remote")?

    I'm guessing your weapon is set to "replicated", so all clients see that the weapon is picked up.

    When you fire the weapon, you need to make an RPC call to basically say "I fired my weapon / I pressed the left mouse button!". So you'd need to call an event that executes on the server. Note that you should keep in mind what elements live on the client and what elements exist on the server (or both). I like referring to this document ( on page 8, there's a good chart to show what lives where. So, for example, if you tried to run an event on the server within a UMG widget, it wouldn't work at all because the server code does not execute for UMG widgets.

    Lets say you are running the code on your character. You have a Left Click event and you have it call another event, "S_WeaponFire" or whatever. S_WeaponFire needs to be set to "Run On server". Now the server knows the weapon is firing. If you want, here you can perform checks to ensure the player has enough ammo or that the weapon is valid, etc. If everything checks out OK, call another event, "MC_WeaponFire" or whatever. MC_WeaponFire is basically just a way to broadcast that the weapon fired to all other players. Set it to Multicast and reliable. Here, you would perform your visual effects like muzzle flash.

    Now you have the basic framework for setting this up. Ideally, you want to perform all your calculations on the server, so within the "S_WeaponFire". If you want to perform a line trace and determine what actors are hit, do it on the server. Effectively, you don't want the clients deciding if they were hit or if they hit another player - the server should make that call.


      Yeah sorry forgot to mention that I don't plan to use dedicated server in any way so it's client 1 with authority.
      Also I do understand the way how replication should work I've managed to make work multiple of them before it's just this one I cannot figure out. So call stack would look like:
      By pressing fire key blueprint interface sends command to the weapon to fire, fire event executes camera shake etc. and at the end calls custom event which should be run on the server (this is where the problem is, it never get's fired) and from that the line trace and effects such as muzzle flash etc should multicast to all clients.
      But don't look for anything complicated in my example take it just like an actor that should do something on server and after that on every client.


        Are you sure you understand replication? Clients don't have authority over anything but themselves, they don't have authority over the servers copy or any other copy. There's a lot of dicey information out there (especially on Youtube) that teaches incorrect techniques. Start with this tutorial series by Epic here.

        The server will always be able to do everything as it should when it's a listen server, in this scenario it has authority over all replicated instances of its character and thus encounters no issues and doesn't require any RPC's to get things to work, the trick is to get things to work on clients.

        I've attached a blueprint that works on listen and dedicated servers for you to study. Hope it helps. It fires a line trace from a "Gun Barrel" (reference your picked up weapon in place of this)

        Also make sure your collisions are set to block whichever sort of line trace you decide to run so you get a hit result. In the below example you need to set the Capsule Component to block visibility. Visibility isn't the best trace to use by any means for a gun but it works for the sake of this example.

        Not the below example runs in a Character Blueprint.
        Attached Files
        Last edited by GrumpyNZ; 10-27-2018, 12:27 PM.


          That weapon if placed in the world is owned by nothing. When it is picked up the server has to SetOwner to something that the client already owns so the client becomes owner of the weapon.

          Ownership is inherited so could be like this "PlayerController<-Character<-Weapon". This means that if you SetOwner on the Weapon to be the Character that the client owns the client now eventually owns that weapon too.

          Note that if a Client try to SetOwner nothing happens. It is ONLY the server that can change Ownership.

          Be careful not to confuse Authority with Ownership.
          Authority is given to whoever spawned the Actor and is never changed. If a client spawns an Actor it will never be able to use any network abilities like sending RPC's or replicating variables.
          Ownership can be changed by the server at any time.
          Last edited by GarnerP57; 10-27-2018, 11:49 AM.


            First and foremost thank you all for finding time to reply, unfortunately I've probably gave too much unimportant informations. I really need to figure out just why custom event with marked run on server is unable to be called by any other client than listen server. That's all. I don't have problem with line trace handling or ownership (I'm not even changing it anywhere).

            I'm now posting here only the relevant part, here is a few events that gets called locally after clicking left mouse button.

            Click image for larger version

Name:	local.png
Views:	355
Size:	57.8 KB
ID:	1545095

            Here is where it gets wrong. HandleFireServer is called only from listen server. Client 1 and any other is unable to call it so every other event after that isn't called and print string "handleFireServer" isn't printed.

            Click image for larger version

Name:	server.png
Views:	358
Size:	88.1 KB
ID:	1545096

            I hope this time I wrote everything important.


              What class(es) are you using to run this in?

              If it is in the PlayerController then there's your problem right there, multicast functions won't work in a PlayerController as they only exist on the Server and Owning client.
              Last edited by GrumpyNZ; 10-29-2018, 08:50 AM.


                Custom class inheriting from the actor.


                  I have been working on a game and accidentally struck a stray key. Now, I cannot move my third person character with the usual key commands unless I hit the "Possess" button. After I quit I get an error message. "Blueprint Runtime Error:Accessed None trying to read property Animinstance from function:'ExecuteUbergraph_ThirdPersonCharacter' from node: (Symbol here like a tilted Q)Branceh in graph: (symbol again)EventGraph in object" (symbol) ThirdPersonCharacter with description: Accessed None trying to read property Animinstance. Does anybody know what this means and how I can get the game back to normal?


                    Doing exactly the same method you've done above everything works as expected with the printscreen nodes. Have you double checked that the blueprint is replicated?

                    Either that or the reference isn't valid (or not replicated).

                    In the below example (on a dedicated server PIE, (but will work fine for listen server too), after having picked up a "Weapon" from the ground and attaching it the "PullTrigger" event is called from the Character's BP and run on the "Weapon" BP. If i understand correctly, this is what you're trying to achieve?

                    The only failure scenario's I could quickly find is turning off replication on either the weapon, the character, or both. OR no having a valid Weapon BP reference (replicate your reference variable too).

                    (Sorryabt the green on green, was just a template map frm mrktplce)
                    Attached Files
                    Last edited by GrumpyNZ; 10-29-2018, 04:43 PM.


                      Originally posted by Mat5i6 View Post
                      ... and from that the line trace and effects such as muzzle flash etc should multicast to all clients.
                      But don't look for anything complicated in my example take it just like an actor that should do something on server and after that on every client.
                      Just a note, the line trace shouldn't be multicast.


                        Exactly, I have just a little more clutter in BP but still, it's pretty much the same and that's what bothers me. Normally my/this setup should work but this is some weird kind of exception. As I've wrote the actor is replicated and always relevant to prevent any issue such as this. Otherwise not even listen server would work which currently does. Also yeah sorry about that that's just my bad grammar, I should have put there ; or something, to separate the line trace and the rest to prevent this confusion. Never the less thanks. I will probably redone this network communication in my weapons system there is obviously some weird problem maybe with clean actor I'll get lucky.


                          Ok, if you want me to take a closer look at the BP you could post the screenshots or something and I could reproduce it. Let me know.


                            Originally posted by Mat5i6 View Post
                            ... That's all. I don't have problem with line trace handling or ownership (I'm not even changing it anywhere).
                            Ownership is what makes "RunOnServer" possible so if the client that calls "RunOnServer" is not the owner of the actor when calling the event the server will drop the event and do nothing (there should be a warning in the log showing that the event was dropped).

                            So make sure that when the client picks up the weapon that the server "SetOwner" on the weapon to the pawn that the client currently possesses.


                              As a side-note "SwitchHasAuthority" is redundant in a "RunOnServer" event. It will always be Authority and never remote because the event can't be executed remotely.