Need help with Multiplayer LAN
I am just starting to make a LAN multiplayer game using blueprints. One thing I read a lot on the internet is that on local multiplayer (I presume this means LAN) games, the Get Player Controller player index input actually is important. Is this true? For example, if I want to get the player character associated with a Game Instance, what I would think to do is inside my Game Instance BP use Get Player Character with player index left at 0. But is this the correct thing to do on LAN multiplayer? Do I need to use the player index input? If I do, then how do I do things like this? How do I find out what index my player associated with that game instance is at?
Thanks for the help!
asked Apr 24 '18 at 04:47 PM in Blueprint Scripting
By trial and error and help from other users I found the following things:
Player Controllers are not shared between server and clients at any level or via any objects, except maybe to let the server know there's a player connected to it remotely, but remote player controllers always have an index of -1 no matter what you try to do to change it. Indexes >=0 mean a player on that same machine, not a remote one.
Player States are replicated and exist on server side and client side but if you want to change them from client you probably have to send a client to server RPC.
Player States have an ID that is unique across all machines, but player controllers' index only exists for the machine they belong to and are used to map to physical devices like game pads, keyboards etc, and to match them up with viewports and to know which one you're grabbing if you don't do it by relation to pawn, owner, etc. (which is usually better).
You can't get a unique ID or index of a remote player controller, not even from the server's side.
You CAN get a unique ID of a Player State from the server's side and the clients' sides.
Player Controllers can possess Pawns, but Player States cannot. However, Player Controllers know which Player State belongs to them.
"Owner" references climb a chain of objects that are related to each other until one is found. Usually with regard to pawns, this finds a player controller.
I think you may confusing split screen which is also ccalled local multiplayer with network play over LAN network. But in issue you describing it does not matter, the point is in any form of multiplayer you dealing with more then one player and each player have specific set of object.
Each player joinging the game have UPlayer object made which is not acceable in blueprints, then from that PlayerController is made which is representation of player control interface, you should be already aware that PlayerController is one possessing the pawns in the world and controls is by feeding it with control data from player, each player have that controller and each player posseses pawn that he controls. There only one Game Instance and only one Game Mode, those aren't associated with any player ,the manage all the players in the world and in networked game they exist only in server.
Now about id input, whatever it is importent depends on which player character or controller (since oyu probably notice there similar ndoe for that) you want to access, you use those only if you really want to address specific player. In most cases you should access those things via relation, for example you got overlap event with a pawn, event return you a actor that cause the event you check if it's pawn, if it's pawn you can check if it is possessed by any player controller and you can get that controller from Get Controller node.Lot of events return actor, pawn and controllers that are related to event, so if you can use those insted,
But if you really want to use those nodes you need to assing IDs yourself in Player Controller , i not sure if UE4 does that automaticly if it does another player will have ID 1 and so on.
answered Apr 24 '18 at 08:56 PM
Follow this question
Once you sign in you will be able to subscribe for any updates here