How to setup input device for second local player

Hello!

I try to add local multiplayer to my project.

I would like to control the first character with mouse and keyboard, and the second with a controller.

I tried to achieve it this way:

void AMyGameMode::StartPlay()
{
        FString Error;
        GEngine->GameViewport->CreatePlayer(1, Error, true);
       
        TArray<APlayerController*> PlayerControllers;
        GEngine->GetAllLocalPlayerControllers(PlayerControllers);
 
        check(PlayerControllers.Num() == 2);
 
        ((AMyPlayerController*)(PlayerControllers[0]))->SetupInputs("P1");
        ((AMyPlayerController*)(PlayerControllers[1]))->SetupInputs("P2");
 
        Super::StartPlay();
}

SetupInputs() function does the input binding, and for every action and axis I create a “P1…” and a “P2…” version, one for the keyboard and mouse, one for the controller. Both P1 and P2 works with the first character. None of them does with the second.

I suppose it is because it doesn’t use the same devices. Is there an easy way to change that? I tried to find a way to do so, without success so far : (

Thanks for reading,

Elathan