From b2bb2a4de09d79712ca0603afdccf4eee2dc4757 Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Mon, 8 Jan 2024 02:40:54 -0500 Subject: [PATCH] CogImGui: Fix cursor hidden on startup if imgui input is enabled --- .../Source/CogImgui/Private/CogImguiContext.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiContext.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiContext.cpp index f4fdc15..5c8be05 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiContext.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiContext.cpp @@ -100,7 +100,6 @@ void FCogImguiContext::Initialize() PlatformApplication->OnDisplayMetricsChanged().AddRaw(this, &FCogImguiContext::OnDisplayMetricsChanged); OnDisplayMetricsChanged(DisplayMetrics); } - } //-------------------------------------------------------------------------------------------------------------------------- @@ -640,6 +639,19 @@ void FCogImguiContext::SetShareMouseWithGameplay(bool Value) //-------------------------------------------------------------------------------------------------------------------------- void FCogImguiContext::RefreshMouseCursor() { + //------------------------------------------------------------------------------------------- + // Focus the main widget when enabling input otherwise the mouse can still be hidden because + // the gameplay might have the focus and might hide the cursor. + //------------------------------------------------------------------------------------------- + if (bEnableInput) + { + FSlateApplication::Get().SetKeyboardFocus(MainWidget); + FSlateApplication::Get().SetUserFocus(0, MainWidget); + } + + //------------------------------------------------------------------------------------------- + // Force to show the cursor when sharing mouse with gameplay for games that hide the cursor + //------------------------------------------------------------------------------------------- if (APlayerController* PlayerController = GetLocalPlayerController(GameViewport->GetWorld())) { if (bHasSavedInitialCursorVisibility == false)