I know it sound easy to do but whatever I try it fail.
I try to get the player controller reference from the character blueprint and for some reason it always fail on clients…
I have try to use (GetPlayerController) and (Get controller) on begin play but it doesn’t work… always return the server controller,
I have try to use on possess event than cast to player controller from new controller and it return server:PlayerController and server: PlayerController1 and Client:PlayerController
It look like the clients are using the server controller…
What I am doing wrong?
GetPlayerController() works different for Server and Client.
For Clients, it returns the local PlayerControllers. For Server, it returns either the local (ListenServer) or the remote Controllers.
The PlayerControllers of other clients do NOT exist on clients. On a client, you only have access to YOUR controllers, You will get NULL/None when you call “getPlayerController(1)” on a client with only one player.
Thanks for the replay! If I understand correctly, on client 1 using GetPlayerController() I should get on print string Client:FPSPlayerController1 but the problem is I get Client:FPSPlayerController. I can’t get the PlayerController 1 on client 1, it give me the server player controller on the client… The local PlayerController on client 1 should be FPSPlayerController1? Right?
No, this is correct behaviour. the PlayerController you retrieve with getPlayerController(0) on the Client is the Client’s PlayerController.
Wrong. GetPlayerController(index) will return whatever PlayerController exist on that index on that computer. So Client 1 will find FPSPlayerController, Client 2 will find FPSPlayerController and so on.
Since the server computer stores all PlayerControllers it will have FPSPlayerController, FPSPlayerController1 etc.
I would recommend you identify who the PlayerController belong to by getting the PlayerState and from there get either the PlayerID or PlayerName. The PlayerController instance number only tells you how many instances have been created during run-time.
You should read this one by @eXi :