Switching gamepad icons at runtime with Common UI

2 min read

This is a quick guide to dynamically switch between different gamepad icons (Xbox, Playstation, Steam Deck...) at runtime using Common UI.

I needed this feature for my upcoming game The Throng, which includes full controller support.

Requirements

  • An Unreal Engine C++ project.
  • Have the Common UI plugin enabled.
  • Have a working set of gamepad icons already setup.

Note

This guide was written for Unreal Engine 5.4, but should work for other versions too.

Steps

Start by adding the "CommonInput" dependency to the PrivateDependencyModuleNames array in the *.Build.cs file.

PrivateDependencyModuleNames.AddRange(new string[]
{
    // ... the rest of our private dependencies (if any)
    "CommonInput",
});

Create a class that inherits the UCommonInputBaseControllerData for each gamepad icons you want to support. For example, my Steam Deck class looks like this:

#pragma once

#include "CoreMinimal.h"
#include "CommonInput/Public/CommonInputBaseTypes.h"
#include "SteamDeckControllerData.generated.h"

UCLASS()
class THE_THRONG_API USteamDeckControllerData : public UCommonInputBaseControllerData
{
	GENERATED_BODY()
	
public:
	USteamDeckControllerData()
	{
        // Replace "Generic" with our desired gamepad name
		GamepadName = GetSteamDeckControllerName();
	}

    // Helper method to change the gamepad icons without misspelling
	UFUNCTION(BlueprintPure)
	static FName GetSteamDeckControllerName()
		{ return FName("SteamDeck"); }
};

Note

Remember to replace THE_THRONG_API with your own API symbols.

Create (or reparent) a Blueprint child for each UCommonInputBaseControllerData subclass created earlier, and check that the Gamepad Name is no longer Generic (even though the dropdown only has the Generic option available).

Image

Remember to also fill the field InputBrushDataMap with your chosen icons, and place the UCommonInputBaseControllerData subclasses in the Project Settings' CommonInputSettings category.

Image

Icons can be switched at runtime using the SetGamepadInputType method.

Image

Conclusion

Now it is possible for our games to automatically switch the selected gamepad icons with ease.

I hope you have learned something new!
Made by Lorwen with ๐Ÿงก

If you liked the guide

I would be very thankful if you could give The Throng a quick look on Steam.

Resources