How to assign a PlayerController to a PlayerID?

Hi,

Can you help me to switch my player controller in realtime with blueprint ?

My GameMode use myPlayerController01, so when the level begin, PlayerID=0 is assigned to myPlayerController01.
Now I want to be able to switch from myPlayerController01 to myPlayerController02 in realtime with blueprint.

I have spawn myPlayerController02 in the level, but how can I assign it to PlayerID=0 ?

Thank you =)

As far as I understand the PlayerController concept, you actually can’t/shouldn’t change it in realtime/during gameplay. You may only have different ones for different worlds. Therefore there is no such function implemented which could be used within Blueprints. However the code definiton of UPlayer includes a function called ‘SwitchController’ expecting a reference to the new PlayerController, but I don’t think you’ll be able to use it without digging deep into the engine code in order to find out how to use it correctly and withoud bad surprises.


However, you could easily work around this issue by creating a custom base (Actor-derived) Blueprint (maybe called ‘InputHandler’ and deriving some specific 'InputHandler’BPs from the base BP. All the input handling is then done in this class (which puts a new level of abstraction into the system - programmers like that :stuck_out_tongue: ). You simply safe a reference to the base class as a variable in your PlayerController. For a better understanding I included four test blueprints which use the functionality just explained.

Another (‘less elegant’ but for small games maybe faster) workaround would be to simply have a variable in the PlayerController which determines the behaviour the player should have and then simply branch by it’s value.

Just wanted to say thanks for that project. That is exactly what I needed!