Common UI's Triggering input action not working when set to controller D-pad

Stumbled on this post while researching how to turn off navigation on the Dpad and ended up finding a solution that works and can be turned off and on at runtime.
Adding this comment for anyone in the future trying to find a solution to this.

So first of all in the constructor of the NavigationConfig.cpp a map called KeyEventRules is setup which is the list of inputs that are supposed to be navigation inputs

FNavigationConfig::FNavigationConfig()
	: bTabNavigation(true)
	, bKeyNavigation(true)
	, bAnalogNavigation(true)
	, AnalogNavigationHorizontalThreshold(0.50f)
	, AnalogNavigationVerticalThreshold(0.50f)
{
	AnalogHorizontalKey = EKeys::Gamepad_LeftX;
	AnalogVerticalKey = EKeys::Gamepad_LeftY;

	KeyEventRules.Emplace(EKeys::Left, EUINavigation::Left);
	KeyEventRules.Emplace(EKeys::Gamepad_DPad_Left, EUINavigation::Left);

	KeyEventRules.Emplace(EKeys::Right, EUINavigation::Right);
	KeyEventRules.Emplace(EKeys::Gamepad_DPad_Right, EUINavigation::Right);

	KeyEventRules.Emplace(EKeys::Up, EUINavigation::Up);
	KeyEventRules.Emplace(EKeys::Gamepad_DPad_Up, EUINavigation::Up);

	KeyEventRules.Emplace(EKeys::Down, EUINavigation::Down);
	KeyEventRules.Emplace(EKeys::Gamepad_DPad_Down, EUINavigation::Down);
}

With this in mind we can just add and remove inputs from this list at runtime to turn on/off navigation for some inputs. To do this you can just add this code to your project and with it you can manually turn on and off the navigation at will

UFUNCTION(BlueprintCallable)
virtual void TurnOffDPadNavigation();
	
UFUNCTION(BlueprintCallable)
virtual void TurnOnDpadNavigation();


void ASomeClass::TurnOffDPadNavigation()
{
	if (FSlateApplication::IsInitialized())
	{
		FSlateApplication::Get().GetNavigationConfig()->KeyEventRules.Remove(EKeys::Gamepad_DPad_Down);
		FSlateApplication::Get().GetNavigationConfig()->KeyEventRules.Remove(EKeys::Gamepad_DPad_Left);
		FSlateApplication::Get().GetNavigationConfig()->KeyEventRules.Remove(EKeys::Gamepad_DPad_Right);
		FSlateApplication::Get().GetNavigationConfig()->KeyEventRules.Remove(EKeys::Gamepad_DPad_Up);
	}
}

void ASomeClass::TurnOnDpadNavigation()
{
	if (FSlateApplication::IsInitialized())
	{
		FSlateApplication::Get().GetNavigationConfig()->KeyEventRules.Emplace(EKeys::Gamepad_DPad_Down);
		FSlateApplication::Get().GetNavigationConfig()->KeyEventRules.Emplace(EKeys::Gamepad_DPad_Left);
		FSlateApplication::Get().GetNavigationConfig()->KeyEventRules.Emplace(EKeys::Gamepad_DPad_Right);
		FSlateApplication::Get().GetNavigationConfig()->KeyEventRules.Emplace(EKeys::Gamepad_DPad_Up);
	}
}
2 Likes