How do i print all player locations in a multiplayer game into an UE log?
Is there different ways to get all player locations?
So can i get all playercontrollers?
For Online Multiplayer, you need to rely on PlayerState
, as that is replicated throughout the network. PlayerController
is only locally available.
But you don’t have to use it at all. What you can do is next. When your pawn enters multiplayer game, and is controlled by the player, you can add it to some list located in GameState
, not GameMode
. When Pawn is destroyed, remove it from that list, as it will not be viable anymore.
Then in your GameState, you can iterate through the pawns, and just use GetActorLocation
to get the location of the Pawn (player).
From the game mode (server) you can iterate the player controllers with:
for (TPlayerControllerIterator<AQAPlayerController>::ServerAll It(GetWorld()); It; ++It)
{
// PC is a AQAPlayerController. It may local or remotely controlled.
AQAPlayerController * PC = *It;
// This can only be done on the server!
// Only the server has player controllers for everyone!
check(GetWorld()->GetNetMode() != NM_Client);
}
Or you can see them in the Outliner if you Play-In-Editor > Play As Client, and then look at the Server world (top right button on outliner panel)
It would be helpful to explain what you’re trying to do. Why do you want to log player locations?