Keyboard = p1 gamepad = p2 please!

If you want a “simpliest” solution without changing the **GameViewportClient **class, you can handle it by “simply” changing the Game Map Settgins in your game instance.
This other class is already call by the GameViewport to check if it should offset (++controllerId) gamepads to “skip associating the first gamepad to the keyboard” (by the variable bOffsetPlayerGamepadIds).

In my case, I expose a function to Blueprints like so :

MyGameInstance.h



    /**
    * Allow to set if keyboard and gamepad should be associate to same player
    */
    UFUNCTION(BlueprintCallable, Category = "Controllers")
    void AssociateGamepadToKeyboard(bool ShouldBeAssociated);


MyGameInstance.cpp



void MyGameInstance::AssociateGamepadToKeyboard(bool ShouldBeAssociated) {
    // Get GameSettings
    auto Settings = const_cast<UGameMapsSettings*>(GetDefault<UGameMapsSettings>());

    // It will affect Gamepad from Controller 1 (and keyboard to 1) if they should not be associated
    Settings->bOffsetPlayerGamepadIds = !ShouldBeAssociated;
}


Do not forget to include (MyGameInstance.h) “GameMapsSettings.h” and add the public dependency (Project.Build.cs) to “EngineSettings”.

1 Like