Change PlayerController on runtime?
I wan't to change the PlayerController that ist controlling the Player character dynamically. The reason is, that I have 2 different Player controller, one for Wiimote input and one for Xbox input. The selection of the PlayerController happens before the level loads in the main menu. I can't combine the two PlayerControllers into one, because the one for the wiimote uses a mouse pointer, while the xbox one doesn't.
I am struggling to find a solution, any help woul be appreciated.
As far as I know, there is no way to change to a different player controller or game mode within the same level. But if you are going to load your level after you know which controller you want, then you use the "Open Level" node and use the "options" input to select a new game mode to load with it, overriding its default game mode setting (the arguments are: "?game=/Game/SomeFolders/yourGameMode", no quotes). You would have two game modes, each one pointing to an alternate game controller, and you would load the same level but with a different game mode depending on the option you chose.
You could also load one of two alternate levels and set a default game mode for each one, but loading with arguments will let you do this without keeping track of a useless duplicate.
Remember that on every level load, you get a chance to change game mode too, with all that it is pointing to (but changing a game mode implies a level loading). Also, remember that if you are casting to the game mode now you have two different possible classes, so take that into account.
If you don't want or can't do that, you can also change the properties of the player controller on the fly.
So you can fire some event on it that will set different properties to true or false, depending on what you need (for example, you could enable or disable click events, or things like that).
The thing is that other blueprints that expect events fired by the things you disabled won't work properly. So you would need to make those functions fire from custom events instead, so they become independent of those properties of the playerController that you want to turn on or off.
And then, on the playerController, you can listen to your two alternative methods of firing that action, and then cast to your player pawn and fire your custom event when either is detected. So the functionality remains the same, independent of what is enabled or not.
You can also have a bool that keeps track of which one of your two alternative functionalities are enabled at a given moment.
Hope this helps. All the best.
Follow this question
Once you sign in you will be able to subscribe for any updates here