How do I determine the owning Player Controller of an actor over network?

I am calling a RPC function from client to server via a RPC. I need some way to determine what Player Controller was the source of the call, so I can do things to that player. I tried passing a PlayerController as a parameter, which was set to null on the other end, and I tried passing a Unique ID but retrieving a player controller via GetPlayerControllerByUniqueID returns a const PlayerController.

I need a way to pick a Player Controller other than just getting the first one in the world. I don’t know if I can pass by player index because those will likely be different on client vs server.

You can’t get other PlayerController on other clients as they are not replicated for security reasons, players have complete access to there memory, so they could read out information they should not have access to. Same goes with GameMode. All exposed information should in APlayerState (created for each APlayerController) and AGameState (created for AGameMode) which are replicated and PlayerState can be accessed from controlled pawn too.

The PlayerState has a unique ID that will be the same across the network.

If you have to find a playercontroller on a different machine, which is associated with the PlayerState that’s on both machines, you can loop through the playercontrollers on either machine and find the one that has the unique ID passed in through the RPC. There is probably a better way, but it works for me.

1 Like