Unreal won't read input from second gamepad

I’ve been screaming my head off from dealing with this issue for the past two hours. Google has been useless. I just get other players asking why their controller and gamepad aren’t separate players (it’s a setting in Maps and Modes, jeez). That’s far from my problem. In fact, I am perfectly capable of reading the keyboard and gamepad as two separate players, one uses WASD and the other uses control stick.

The issue happens when I attempt to make a second or third player using another gamepad. My game just flat-out ignores any gamepad beyond index 0. By that, I mean, in HTML5Gamepad.com, it shows there are two gamepads connected: an Xbox One gamepad(index 0) and an XBox 360 gamepad (index 1). However, no matter what I do on my end, Unreal can see the controller in index 1 (I can move around the Editor interface with it), but in-game, the second gamepad pretends to not exist, and sends absolutely not input to any player.

Here’s my code:

void AProjectPlighterGameMode::BeginPlay()
{
	GetGameInstance()->GetGameViewportClient()->MaxSplitscreenPlayers = 5;
	GameCamera = GetWorld()->SpawnActor<APlatfightanCameraActor>(FVector(0, 0, 0), FRotator::ZeroRotator);

	TArray<APlayerController*> PArray;

	AActor* TheStartPos;
	TSubclassOf<AFighterClassCharacter> FighterSpawn;
	FFightingPlayer PersPly;
	AFighterClassCharacter* NewFighter;

	PArray.Add(UGameplayStatics::GetPlayerController(GetWorld(), 0));
	PArray.Add(UGameplayStatics::CreatePlayer(GetWorld(), 1, true));
	PArray.Add(UGameplayStatics::CreatePlayer(GetWorld(), 2, true));
	PArray.Add(UGameplayStatics::CreatePlayer(GetWorld(), 3, true));
	PArray.Add(UGameplayStatics::CreatePlayer(GetWorld(), 4, true));

	class UProjectPlighterGameInstance* GameInst = Cast<UProjectPlighterGameInstance>(GetGameInstance());
	if (GameInst)
	{
		if (!GameInst->NotATest)
		{
			GameInst->PersistentPlayers[0].ControllerID = 0;
			GameInst->PersistentPlayers[0].PlayerCharacter = FName(TEXT("cait"));
			GameInst->PersistentPlayers[0].IsPlaying = true;
			GameInst->PersistentPlayers[1].ControllerID = 1;
			GameInst->PersistentPlayers[1].PlayerCharacter = FName(TEXT("gree"));
			GameInst->PersistentPlayers[1].IsPlaying = true;
			GameInst->PersistentPlayers[2].ControllerID = 2;
			GameInst->PersistentPlayers[2].PlayerCharacter = FName(TEXT("redg"));
			GameInst->PersistentPlayers[2].IsPlaying = true;
			GameInst->PersistentPlayers[3].ControllerID = 3;
			GameInst->PersistentPlayers[3].PlayerCharacter = FName(TEXT("NULL"));
			GameInst->PersistentPlayers[3].IsPlaying = true;
		}
		for (uint8 i = 0; i < 4; i++)
		{
			PersPly = GameInst->PersistentPlayers[i];
			if (PersPly.IsPlaying)
			{
				TheStartPos = ChoosePlayerStart(PArray[PersPly.ControllerID]);
				FighterSpawn = GameInst->GetClassFromFName(PersPly.PlayerCharacter);
				NewFighter = GetWorld()->SpawnActor<AFighterClassCharacter>(FighterSpawn, TheStartPos->GetActorLocation(), FRotator::ZeroRotator, FActorSpawnParameters());
				if (IsValid(NewFighter) && IsValid(PArray[PersPly.ControllerID]) && IsValid(PArray[PersPly.ControllerID]->GetLocalPlayer()))
				{
					PArray[PersPly.ControllerID]->Possess(NewFighter);
				}
				else UE_LOG(LogTemp, Error, TEXT("NewFighter or controller did not spawn"));

			}
		};
	};
}

With this code, cait, redg, gree, and null all spawn in the level as expected. cait receives input from the keyboard, gree receives input from the XBOX One controller, and redg and null receive no input whatsoever. Their PlayerControllers exist and are valid, and they are possessed correctly, but they don’t mode. None of the controller inputs show up from the x360 controller when using showdebug input either.

When investigating, I found the inverse occurred when I plugged in the x360 controller before the XBOX One controller; that is, cait received the keyboard, gree received the x360 controller, and the XBOX One controller was completely ignored. So, whatever is gamepad index 1 just… doesn’t get read at all.

What am I doing wrong???

Is it maybe because you skip assigning the gamepad to the first player? Have you got another controller so you can check and see if it works only using controllers with the keyboard and mouse also having a gamepad assigned to the same character?

read the question again.

My game just flat-out ignores any gamepad beyond index 0. By that, I mean, in HTML5Gamepad.com, it shows there are two gamepads connected: an Xbox One gamepad(index 0) and an XBox 360 gamepad (index 1).

cait receives input from the keyboard, gree receives input from the XBOX One controller, and redg and null receive no input whatsoever.
I AM NOT having an issue with getting input for two players. I am having an issue with two GAMEPADS.

Welp. Today I feel really salty. Figured out how to fix it myself.

So, note to everyone else:

Don’t create / possess new players in Begin Play.

As soon as I put all the character spawns behind a timer, everything worked out all hunky-dory. So that’s just grand.

1 Like

Thanks. I have the same issue.

I try your solution and indeed it works now…

So my question is where to create character? if it’s not inside the BeginPlay of the GameMode?