How to get an APlayerController or camera on a server in C++.

Hi. I am using APlayerController to get APlayerCameraManager to get camera coordinates (for LineTraceSingleByChannel).

If I use on the server

GameplayStatics::GetPlayerController(this, 0)

then I only get the APlayerController for the first player.

How to get the ID for the APlayerController ? Or is there another way to get a specific APlayerController inside APawn ? Or another way to get the current camera coordinates of a specific APawn.

I’m not so experienced, but answer may be the trying to solve the problem from different perspective. Instead of directly trying to find the player:

  • Can you select the player with line-tracing from some object?
  • Can you get all players in the game then choose one?
  • Maybe you can access via some outer?
  • If you doing some editor code, it can be also good idea to send line-trace by editor whenever you click on the character u want to choose.

Based on the ID solution, I think retrieve all players then using array can work. I remember there were such method.