Error14. 默认导航导致的UI关闭不了
大约 2 分钟
省流
UE默认导航Tab键会聚焦拦截UI,导致Input事件传递不下去
问题描述
问题排除
- 论坛解决方案:在PlayerController中加入
#include "Framework/Application/NavigationConfig.h"
void AMyPlayerController::ToggleThumbstickUiNavigation(bool ThumbstickNavigationEnabled) {
if (FSlateApplication::IsInitialized()) {
TSharedRef<FNavigationConfig> currentNavConfig = FSlateApplication::Get().GetNavigationConfig();
currentNavConfig->bAnalogNavigation = ThumbstickNavigationEnabled;
FSlateApplication::Get().SetNavigationConfig(currentNavConfig);
}
}
- 封装成蓝图函数库

#include "Framework/Application/NavigationConfig.h"
/**
* Toggles various types of UI navigation.
* Enables or disables specific navigation behaviors in the UI, including tab-based navigation,
* key-based navigation, and analog thumbstick navigation.
*
* 切换各种类型的 UI 导航。
* 启用或禁用特定的 UI 导航行为,包括基于 Tab 键的导航、键盘导航和模拟摇杆导航。
*
* @param bTabNavigation Enables or disables Tab key navigation.
* 启用或禁用 Tab 键导航。
* @param bKeyNavigation Enables or disables navigation using keyboard keys.
* 启用或禁用键盘导航。
* @param bAnalogNavigation Enables or disables analog (thumbstick) navigation.
* 启用或禁用模拟摇杆导航。
*/
UFUNCTION(BlueprintCallable, Category = "UI|Navigation")
static void ToggleThumbstickUiNavigation(bool bTabNavigation = true, bool bKeyNavigation = true, bool bAnalogNavigation = true);
void UInventoryLib::ToggleThumbstickUiNavigation(bool bTabNavigation /*= true*/, bool bKeyNavigation /*= true*/, bool bAnalogNavigation /*= true*/)
{
if (FSlateApplication::IsInitialized())
{
// Get the current navigation configuration.
// 获取当前的导航配置。
const TSharedRef<FNavigationConfig> CurrentNavConfig = FSlateApplication::Get().GetNavigationConfig();
// Set navigation switches.
// 设置导航开关。
CurrentNavConfig->bTabNavigation = bTabNavigation;
CurrentNavConfig->bKeyNavigation = bKeyNavigation;
CurrentNavConfig->bAnalogNavigation = bAnalogNavigation;
// Apply the new configuration.
// 应用新的配置。
FSlateApplication::Get().SetNavigationConfig(CurrentNavConfig);
}
}