How do i get the player locations in C++

Thats what i could write in c++ but i still got player location (0,0,0). Why?? and how can i get the player location of all players in game

You need reference to the PlayerArray, then just use GetActorLocation(). Just make sure PlayerArray is properly filled. Are you sure you have proper reference there? Is array defined in C++?

how do i get the player array reference in bp or in c++

PlayerArray is list of PlayerStates, not PlayerControllers. This is the reason you are getin 0 all the time. If you need this info on the server only, you can get player controllers, and then player Pawns from player controllers. But that is a bit tricky.

What you can do is, just make sure pawns are stored in some list, inside of GameState on BeginPlay, and removed on Destroyed. Then you can iterate through that list and use GetActorLocation() to get location.

Another, maybe more viable option is to have some static list of StructObject. One parameter of a struct would be identifier for the player (whatever you want to use to identify the player), and second would be location. This can also be some inside some list, and therefore you can get the player that you want, and it’s location. This will avoid storing whole Pawn in game state, and storing only the info that you need.

1 Like