How to get IPlatformInputDeviceMapper?

I ran into this issue today.

To expand on this a bit more, add this to your header file:

UFUNCTION()
		void OnControllerChanged(EInputDeviceConnectionState connectionState, FPlatformUserId userID, FInputDeviceId inputDeviceID);

Connect to the delegate:

void SOMEFILE::BeginPlay()
{
	Super::BeginPlay();	

IPlatformInputDeviceMapper::Get().GetOnInputDeviceConnectionChange().AddUObject(this, &SOMEFILE::OnControllerChanged);	
}

Function that gets called:

void SOMEFILE::OnControllerChanged(EInputDeviceConnectionState connectionState, FPlatformUserId userID, FInputDeviceId inputDeviceID)
{
	UE_LOG(LogTemp, Warning, TEXT("Controller changed!"));

	if (connectionState == EInputDeviceConnectionState::Disconnected)
	{
		UE_LOG(LogTemp, Warning, TEXT("Controller disconnected!"));
	}
}
5 Likes