How can I get my own PlayerController on my Listen server?
Getting your own PC is easy on both standalone and client(they are actually the only PlayerControllers) but I cannot figure out how to get the PlayerController that belongs to the host in a Listen game
asked Dec 18 '14 at 03:56 AM in C++ Programming
I know it's an old question, but I had encoutered the same kind of issue. So I'll to explain 2-3 things.
You have to separate two things : Controller ID and Controller Index.
The index is the position in the world player controller's array. It may change for the same controller especially in a Listen Server after a seamless travel with a controller swap (ex : if changing the class).
The ID (indentifier) of the controller is store in the LocalPlayer and is unique for each local controller, where 0 is the "main" controller that can be used for referencing HUD & Widgets.
So " the controller on index 0 is always "your player controller" " is not true. If you need the main controller, you have to add a little C++ function like so :
Hope it'll help some other devs !
answered Jun 25 '18 at 03:36 PM
Only the server has all the player controllers, so you can only get the APlayerController of the host on the actual host.
AFAIK the controller on index 0 is always "your player controller", so if you're calling the following in the server, it returns the host player controller:
If you do it on a client, it returns their player controller, and remember that in the clients the other player controllers do not exist
Also, in the change that server is dedicated, call IsLocalPlayerController() on the return from that function above, if it returns false it is a dedicated server (hence the host has no player controller).
answered Apr 19 '15 at 09:20 PM
Solution C++ Code For You
NAfonso's answer is very good.
I also just answered this over here!
answered Apr 21 '15 at 08:49 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here