Announcement

Collapse
No announcement yet.

Multiplayer Question On Switch Has Authority

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

    Multiplayer Question On Switch Has Authority

    Hi, I am now to the point where I'm doing replication and the networking part of my project. I think I have a good grasp on how this works but have a simple question, maybe. I have a sort of a shooter game and my characters fire bullets, should I use switch has authority when spawning the projectiles? or is just making a custom event and set to run on server then multicast a better way? or do both together? But from what I have read is that switch has authority should be used to prevent cheating. I have taken a look at a few projects from the marketplace that have multiplayer enabled and in their whole project they only call switch has authority a few times in the whole project... this seems strange because wouldn't you want everything you could to be ran through the switch to prevent cheating?

    All comments welcome to help me figure out the best plan, thanks

    #2
    Had similar "fun" with replication few months ago, turns out if you want to handle shooting on server to prevent cheating just use an event which is set to run on the server, handle there all the calculations and apply damage and multicast effects to all. Most of the time you don't really need that switch. Just watch out for actor ownership if the actor is not owned by a controller and you call any replication event, the event just won't work and nothing will happend (learned that the hard way) in that case the switch might come in handy.

    Comment


      #3
      Originally posted by Mat5i6 View Post
      Had similar "fun" with replication few months ago, turns out if you want to handle shooting on server to prevent cheating just use an event which is set to run on the server, handle there all the calculations and apply damage and multicast effects to all. Most of the time you don't really need that switch. Just watch out for actor ownership if the actor is not owned by a controller and you call any replication event, the event just won't work and nothing will happend (learned that the hard way) in that case the switch might come in handy.
      Awesome input! Thanks

      Comment


        #4
        A basic implementation of spawning a bullet could look like this.
        Pawn Client-side "Fire Button Pressed" input event > RunOnServer Event "FireButtonPressed"
        Pawn Server-side "FirebuttonPressed" received > SpawnActorOfClass (Make sure the Bullet Blueprint is set to Replicate)

        There is no need to also make a Multicast event back to the client that called it or the other clients, since it is implicitly called with BeginPlay when the bullet is replicated to the clients.

        This method will however not be a very good experience for the player that fired the bullet since the bullet will not appear instantly when pulling the trigger.
        In some cases you can obscure this by triggering a VFX locally when the trigger is pulled but if that is not good enough you would spawn a bullet locally and use lag compensation on the server to determine the hit location.

        "Movement prediction" and "Lag compensation" is something every fast paced networked game has to deal with to give a better multiplayer experience and is a topic in itself.
        Last edited by GarnerP57; 01-25-2019, 11:29 AM.

        Comment


          #5
          "SwitchHasAuthority" in itself is not what prevents cheating it just helps distinguish Server from Client. To prevent cheating you need to sanitize the input coming from the clients and reject it if it trying to do something illegal.

          If you have something that the clients should not be able to tamper with it will exist only on the server and then there is no need for "SwitchHasAuthority".

          Comment


            #6
            Originally posted by GarnerP57 View Post
            "SwitchHasAuthority" in itself is not what prevents cheating it just helps distinguish Server from Client. To prevent cheating you need to sanitize the input coming from the clients and reject it if it trying to do something illegal.

            If you have something that the clients should not be able to tamper with it will exist only on the server and then there is no need for "SwitchHasAuthority".
            Thank you for the explanations!

            Comment

            Working...
            X