CommonUI and multiple controller types

I actually found what i changed in the engine

In CommonInputBaseTypes.cpp i changed the GetBestGamepadNameForHardware into this

FName UCommonInputPlatformSettings::GetBestGamepadNameForHardware(FName CurrentGamepadName, FName InputDeviceName, const FString& HardwareDeviceIdentifier)
{
    InitializeControllerData();

    FName FirstMatch = NAME_None;

    for (const TSubclassOf<UCommonInputBaseControllerData>& ControllerDataPtr : ControllerDataClasses)
    {
        if (const UCommonInputBaseControllerData* DefaultControllerData = ControllerDataPtr.GetDefaultObject())
        {
            bool bThisEntryMatches = false;
            for (const FInputDeviceIdentifierPair& Pair : DefaultControllerData->GamepadHardwareIdMapping)
            {
                if ((Pair.InputDeviceName == InputDeviceName) && (Pair.HardwareDeviceIdentifier == HardwareDeviceIdentifier))
                {
                    bThisEntryMatches = true;
                    break;
                }
            }

            if (bThisEntryMatches)
            {
                if (CurrentGamepadName == DefaultControllerData->GamepadName)
                {
                    return CurrentGamepadName;
                }

                if (FirstMatch == NAME_None)
                {
                    FirstMatch = DefaultControllerData->GamepadName;
                }
            }
        }
    }

    return FirstMatch.IsNone() ? FCommonInputDefaults::GamepadGeneric : FirstMatch;
}

in CommonInputPreprocessor.cpp at line 218 i have changed the code to this

// Try to auto-detect the type of gamepad
if (InputMethod == ECommonInputType::Gamepad
    && ICommonInputModule::GetSettings().GetEnableAutomaticGamepadTypeDetection()
    && UCommonInputPlatformSettings::Get()->CanChangeGamepadType())
{
    if (const FInputDeviceScope* DeviceScope = FInputDeviceScope::GetCurrent())
    {
        if ((DeviceScope->InputDeviceName != LastSeenGamepadInputDeviceName) || (DeviceScope->HardwareDeviceIdentifier != LastSeenGamepadHardwareDeviceIdentifier))
        {
            LastSeenGamepadInputDeviceName = DeviceScope->InputDeviceName;
            LastSeenGamepadHardwareDeviceIdentifier = DeviceScope->HardwareDeviceIdentifier;

            const FName BestGamepadType = UCommonInputPlatformSettings::Get()->GetBestGamepadNameForHardware(NAME_None, DeviceScope->InputDeviceName, DeviceScope->HardwareDeviceIdentifier);
            if (BestGamepadType != InputSubsystem.GetCurrentGamepadName())
            {
                InputSubsystem.SetGamepadInputType(BestGamepadType);
                OnGamepadChangeDetected.Broadcast(BestGamepadType);
            }
        }
    }
}
1 Like