Problem with Enhanced Input and Split Screen on UE 5.1

Hello everyone,

I also have this issue, and while I got it to work in the editor, it does not work in the executable.
I did however find a solution in my game. Small intro, my game is a 2-player adversarial game. Each player controls a character and battles each other to see who wins.

I found that the first time I initialize my second player, it will fail to grab the input device, but if I delete the first instantiation and create a new second player, it will grab the gamepad.

To get the input to work I did the following. In my custom Gamemode:

// HEADER
class ACustomGameMode // ...
{
        
	UFUNCTION()
	void DelayedBeginPlay();
}
// CPP
void ACustomGameMode::BeginPlay()
{
	Super::BeginPlay();
        // ... more code ...

        // Create a player controller
	SecondPlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 1);
	if (!SecondPlayerController)
	{
		SecondPlayerController = UGameplayStatics::CreatePlayer(GetWorld(), 1);
	}

        // Set a timer for a delayed BeginPlay
	if (GetWorld())
	{
		GetWorld()->GetTimerManager().SetTimer(DelayedBeginPlayTimer, this, &ABestOutOfGameMode::DelayedBeginPlay, 0.2f);
	}
}

void ACustomGameMode::DelayedBeginPlay()
{
        // Delete the Player Controller we created
	SecondPlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 1);
	if (SecondPlayerController)
	{
		UGameplayStatics::RemovePlayer(SecondPlayerController, false);
		SecondPlayerController = nullptr;
	}

        // Create a new Player Controller
	if (!SecondPlayerController)
	{
		SecondPlayerController = UGameplayStatics::CreatePlayer(GetWorld(), 1);
	}
}

Furthermore, I followed the instructions by @davabase and it seems to work. I do propose another solution that seems to work for me, which is to override the PossessedBy() function and call the BindInputs() there.


void AMyCharacter::PossessedBy(AController* NewController)
{
	Super::PossessedBy(NewController);
	
	BindInputs();
}

It seems to work for me. Try it out and let me know if it works for you.

1 Like