HardwareDevices

HardwareDevices

#Overview

name: HardwareDevices

The value of this variable can be defined or overridden in .ini config files. 4 .ini config files referencing this setting variable.

It is referenced in 4 C++ source files.

#Summary

#Usage in the C++ source code

The purpose of HardwareDevices is to maintain a list of identifiable hardware input devices available on a specific platform within the Unreal Engine 5 input system.

This setting variable is primarily used by the Engine’s input system, specifically within the InputSettings module. It’s part of the UInputPlatformSettings class, which is a subclass of UPlatformSettings, indicating its role in platform-specific input configurations.

The value of this variable is set in multiple places:

  1. In the constructor of UInputPlatformSettings, where default devices (Invalid, KeyboardAndMouse, Gamepad, and MobileTouch) are added.
  2. Through the AddHardwareDeviceIdentifier function, which allows adding custom hardware devices.
  3. It can also be configured through the Unreal Engine editor, as indicated by the UPROPERTY(config, EditAnywhere, Category = “Hardware”) decorator.

HardwareDevices interacts with FHardwareDeviceIdentifier structures, which represent individual input devices. It’s used in conjunction with other functions like GetHardwareDeviceForClassName to retrieve specific device information.

Developers should be aware of the following when using this variable:

  1. It’s platform-specific, so different platforms may have different sets of hardware devices.
  2. The list includes default devices that are always present (Invalid, KeyboardAndMouse, Gamepad, MobileTouch).
  3. Custom hardware devices can be added to this list.

Best practices when using this variable include:

  1. Always check for the existence of a device before using it, as not all devices may be available on all platforms.
  2. Use the provided functions (like GetHardwareDeviceForClassName) to access device information rather than directly manipulating the array.
  3. When adding custom devices, ensure they have unique identifiers to avoid conflicts with existing devices.
  4. In editor tools, consider using GetAllHardwareDeviceNames to get a comprehensive list of devices across all platforms.
  5. Remember that this is a configuration property, so changes made in runtime won’t persist unless explicitly saved to config.

#Setting Variables

#References In INI files

Location: <Workspace>/Engine/Config/Windows/WindowsInput.ini:2, section: [InputPlatformSettings_Windows InputPlatformSettings]

Location: <Workspace>/Engine/Plugins/Runtime/Steam/SteamController/Config/Input.ini:2, section: [InputPlatformSettings_Windows InputPlatformSettings]

Location: <Workspace>/Engine/Plugins/Runtime/Windows/WinDualShock/Config/Input.ini:2, section: [InputPlatformSettings_Windows InputPlatformSettings]

Location: <Workspace>/Engine/Plugins/Runtime/Windows/WinDualShock/Config/Input.ini:3, section: [InputPlatformSettings_Windows InputPlatformSettings]

#References in C++ code

#Callsites

This variable is referenced in the following C++ source code:

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Classes/GameFramework/InputSettings.h:564

Scope (from outer to inner):

file
class        class UInputPlatformSettings : public UPlatformSettings

Source code excerpt:

	/** A list of identifiable hardware devices available on this platform */
	UPROPERTY(config, EditAnywhere, Category = "Hardware")
	TArray<FHardwareDeviceIdentifier> HardwareDevices;
};

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UserInterface/InputSettings.cpp:638

Scope (from outer to inner):

file
function     UInputPlatformSettings::UInputPlatformSettings

Source code excerpt:

	// Add the default invalid and KBM hardware device ID's here so that they will
	// be found if no custom devices exist when you call GetHardwareDeviceForClassName
	HardwareDevices.AddUnique(FHardwareDeviceIdentifier::Invalid);
	HardwareDevices.AddUnique(FHardwareDeviceIdentifier::DefaultKeyboardAndMouse);
	HardwareDevices.AddUnique(FHardwareDeviceIdentifier::DefaultGamepad);
	HardwareDevices.AddUnique(FHardwareDeviceIdentifier::DefaultMobileTouch);
}

UInputPlatformSettings* UInputPlatformSettings::Get()
{
	return UPlatformSettingsManager::Get().GetSettingsForPlatform<UInputPlatformSettings>();
}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UserInterface/InputSettings.cpp:651

Scope (from outer to inner):

file
function     const FHardwareDeviceIdentifier* UInputPlatformSettings::GetHardwareDeviceForClassName

Source code excerpt:

const FHardwareDeviceIdentifier* UInputPlatformSettings::GetHardwareDeviceForClassName(const FName InHardwareDeviceIdentifier) const
{
	return HardwareDevices.FindByPredicate(
		[InHardwareDeviceIdentifier](const FHardwareDeviceIdentifier& Hardware)
		{
			return Hardware.HardwareDeviceIdentifier == InHardwareDeviceIdentifier;
		});
}

#Loc: <Workspace>/Engine/Source/Runtime/Engine/Private/UserInterface/InputSettings.cpp:662

Scope (from outer to inner):

file
function     void UInputPlatformSettings::AddHardwareDeviceIdentifier

Source code excerpt:

	if (ensure(InHardwareDevice.IsValid()))
	{
		HardwareDevices.AddUnique(InHardwareDevice);
	}
}

const TArray<FHardwareDeviceIdentifier>& UInputPlatformSettings::GetHardwareDevices() const
{
	return HardwareDevices;
}

#if WITH_EDITOR
const TArray<FName>& UInputPlatformSettings::GetAllHardwareDeviceNames()
{
	static TArray<FName> HardwareDevices;
	HardwareDevices.Reset();

	// Add the keyboard and mouse by default for everything
	HardwareDevices.Add(FHardwareDeviceIdentifier::DefaultKeyboardAndMouse.HardwareDeviceIdentifier);

	// Get every known platform's InputPlatformSettings and compile a list of them
	TArray<UPlatformSettings*> AllInputSettings = UPlatformSettingsManager::Get().GetAllPlatformSettings<UInputPlatformSettings>();

	for (const UPlatformSettings* Setting : AllInputSettings)
	{
		if (const UInputPlatformSettings* InputSetting = Cast<UInputPlatformSettings>(Setting))
		{
			for (const FHardwareDeviceIdentifier& Device : InputSetting->HardwareDevices)
			{
				HardwareDevices.AddUnique(Device.HardwareDeviceIdentifier);
			}
		}
	}

	return HardwareDevices;
}
#endif	// WITH_EDITOR