Announcement

Collapse
No announcement yet.

Does each player have a player controller in multiplayer?? [Question]

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

    Does each player have a player controller in multiplayer?? [Question]

    I'm a little confused about how to set up a multiplayer game (online).

    My initial understanding of the setup was
    • Each player has a player controller which gives them control of the game
    • The results of any actions by a player using a player controller would be replicated on the server, minus the performance issues.

    This is important to me, because if every player has to do all of the calculations for every player's actions on their own PC at once, I don't think my game idea is valid performance wise. Whereas if the players only have to do the calculations for their own actions, and just see the server's replication of the other actions, it would work.

    So my questions would be:
    • Does each player have a single player controller that gives them access to controls
    • Does replication mean that no one else has to take a performance hit from the actions (for example if a group of characters is moved, and needs to use event tick to work correctly, does that tick happen on everyone's machine?)
    • What is the general hierarchy of classes and their purposes when it comes to multiplayer?

    If anyone can help me understand or point me in the right direction that would be great!

    #2
    I'm no 'authority' on MP but I'll get things started... This concise doc spells out your options:

    https://docs.unrealengine.com/en-US/...nts/index.html

    You could do 'Run on Owning Client' to ensure things only run on that particular Client. You could also Spawn an Actor 'locally', so actions will also not be replicated. Then use logic like: isLocallyControlled and Switch-Has-Authority 'true' to allow you to branch to that code *uniquely* for the Client that owns the actor with 'all the calculations' etc...

    Overall, the doc makes it very clear that NOTHING is ever replicated from Client to Server. Its only ever the-other-way-around. Normally the way the Client actually communicates with the Server, is to call Run-On-Server and pass it parameters (which is the exact opposite of what you want here)....

    As regards the other questions: PC's etc. Basically each player has one. If the Server is a Listen-Server it gets one as well. But if its a Dedicated Server then there's none. In general Actors do Tick on all the other Clients plus the Server (Server-Spawned / Level-Spawned anyway). But my understanding is, not if the actor is spawned locally on one Client... But you can branch the code / logic anyway using clauses such as IsServer / IsLocallyControlled / HasAuthority etc.

    Comment


      #3
      I'm no expert but I've been dealing with UE4 multiplayer for a while.

      When a client connects to a server, there are two player controllers that exist: the client version and the server version. Both run the same code and the flow of that code can be controlled using "Authority" switches.

      One thing to keep in mind: "Replication" means communication from SERVER to CLIENT. If a client tries to "replicate" something, it will do nothing. So on an actor if you check "Replicates" in the class defaults, this means "If this actor spawns or is destroyed on the server, it will be spawned or destroyed for each connected client as well".

      If you check "Replicate Movement" (or maybe it's "Movement Replicates", I don't remember) AND "Replicates" is checked it means "If this actor moves using a movement component on the server, the corresponding client version of this actor will move as well".

      I believe that is ALL the built in client/server communication that exists. You will need to code the rest yourself. So lets say you have an "Enter" node in your controller blueprint graph to capture when you press Enter on your keyboard and lets say you want this to play a 2D sound at your location. If you connect a "Play sound at location" node, only you will ever hear it - no other connected players will hear it. The way to get this action to broadcast to other players is to first tell the server "I pressed enter" then to have the server replicate to all connected clients. So create a new event, something like "S_PlaySound" and under the event properties for replication use "Run On Server". This creates an RPC - Remote Procedure Call which is used for one client to communicate information to the server. Also, I prefix my events based on how they are replicated - it makes it easier to see at a glance. S_ for "Run On Server", C_ for "Run on Owning Client", MC_ for "Multicast". But that's not a requirement. So now connect a call to this "S_PlaySound" to your "Enter" event. If you do a print from S_PlaySound, you'll see the server prints "Hello". So now create another new event, called "MC_PlaySound", for the replication properties set it to "MultiCast" then call it from S_PlaySound. From MC_PlaySound, connect your "Play Sound at Location".

      So to answer your questions
      - "Does each player have a single player controller that gives them access to controls": Effectively, yes. Each player has a single player controller.
      - "Does replication mean that no one else has to take a performance hit from the actions (for example if a group of characters is moved, and needs to use event tick to work correctly, does that tick happen on everyone's machine?)": This can be optimized how you choose. Not everything needs to be calculated on the server. For example, if you're trying to decide if a player pawn intersected with a collision box, this is best done on the server - it is the authority. If you want to do something like have a ragdoll corpse get lobbed into the air but it doesn't really matter where it lands because it's all just visual effect then it doesn't really need to be synchronized across all clients. The server can just tell the clients "Lob this actor, simulate your own physics and let it land wherever".
      - "What is the general hierarchy of classes and their purposes when it comes to multiplayer?": Not certain what you're asking here but I think the link from the previous post should answer this.

      Comment


        #4
        The bible

        http://cedric-neukirchen.net/Downloa...Neukirchen.pdf

        This will give you a good understanding of the hierarchy of classes

        Comment

        Working...
        X