What does Get Player Controller (Player index = 0) return in multiplayer?

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.

5 Likes

Thank you for the quick, straightforward answer! This is exactly what I was looking for.