CommonUI and multiple controller types

I’m using CommonUI and CommonInput to handle the UI when changing input device (M&K, Xbox controller, PS5 controller). I have a widget that i’m testing on where there’s only a WBP_InputAction that has a Triggering Input Action set as this (see image). Problem is, if i have a DualSense controller and an Xbox controller connected, if i use the PS5 controller the UI switches to the correct images, but when i use the xbox controller the ui doesn’t switch to the correct images and it still displays the PS5 ones.

How do i achieve the intended behaviour?

This is how my project setting is setup

I also made this to test if the controller switch was recognized but when i use the PS5 controller and then switch to the xbox one, i get PS5 CONTROLLER printed on screen, so i guess it’s not recognizind that i’m switching between controllers

1 Like

I’m at the same cross-roads. Did you find anything?

Input action can be problematic in a lot of cases, the common ui input is not a very good solution it that terms to be honest especiialy when multiple inputs connected. However your single problem is gamepad name is not something like PS5 probably writing something else already there.

There are player cases with keyboard + gamepad input. Player uses gamepad for movement and keyboard for presses and vice versa, sometimes it causes flickers in different input too.

Here is my custom UIInputAction Handler widget. It is quite handy and extendable and much more easier to use :slight_smile:

Here its blueprint scripts (hope its readable but also snippet can be accessed from here)

Here is the widget hierarcy, I have a custom widget type but its just a user widget after all. When you define an input on it, it basically searches appropiate icon from database for the appropiate input and displays it to player.

Here is the data table and a simple struct for image library.

and even think I will share the table as Json so future visitors can found input names list without doing excel work.
InputIconsList.json (36.5 KB) and icons name organised
NameOrganisedInputIcons.zip (623.4 KB)

I use generic/universal icons for my setup on gamepad, however you can add brand specific ones and select them with ease. On top of these custom umg behind in c++ asks something specific for a movement input and considers this as main input, so if there is setups like gamepad + keyboard it doesn’t flicker. Maybe I should sell it or extend commonui code as beleif in free code.

If you want to just detect input changed event and identify it as specific to various type you can use this below to identify.

As mentioned you can just use event for it, but if you want to debug on tick.

Still afaik name can be different on different versions and depends ofcourse how hardware recognised in player operating system.
Hope it helps.

Also want to correct myself and give the right information.

If this is old input system think its different also RawInput is needed to properly detect

GetRawInputDeviceInfo() would anyway return the correct input identifier.

Some time has passed since this post. I believe i fixed this issue by modifying the engine source. I cannot recall what exactly i have changed, if it’s still relevant i can try and see the changes i made.

I appreciate the extensive reply Grimnir has made, i hope it can help others with similar issues

No worries, I will write a input handler soon for my project soon, so it was a refreshment for me too.

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

Nice, bookmarking this :slight_smile: think I will need it.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.