Hello all!
I feel like this is a pretty simple one, but I can’t wrap my head around it.
In a multiplayer game with a dedicated server and multiple players in the level, what will GetPlayerController(0) return?
What if it’s not a dedicated server game?
Is the answer different when the code runs on the server or on each of the clients?
My first guess is that the first player spawned into the level has the index 0. My second guess is that the index 0 is always with the “local” player for clients; not sure what it would be for the server. I’m edging towards guess 1 at the moment.
Player 0 is the first player created on the machine that is running the code.
So if you have 2 players on the Server and 2 players on a client and 2 players on another client for a total of 6 players in the game over 3 computers,
then the server’s 2 players will be at index 0 and 1,
and client A’s 2 players will be at index 0 and 1 on their machine. they will also be on the server’s machine but who knows what index they’ll be at there, and they’ll have IDs of -1 because they dont belong to the server machine.
client B, exact same situation.
So server will see 6 player controllers but only its own will have IDs >= 0 the others have IDs == -1
Each client will only see its own playercontrollers.
6 Likes
Thank you for the quick, straightforward answer! This is exactly what I was looking for.
If the Player State exists at index 0 on the client and index X on the Server, what happens when I use a BP_Interface to send a message to the Player State?
In this situation, the Player State has the same BP_Interface implemented in its classes, and I plug fGetPlayerState into the target using index 0.
Do I send a BP_Interface message to both my Player State and the Player State of a client at index 0 on the server? (causing either a double activation on my side or a seemingly random activation for another player)
Does the Server take up a player 0 slot? (it’s not a player, but systems be arbitrary)
Do I only send the message to my own Player State because I’m player index 0 to myself?
Is there a better way to implement this?