Trouble with input focus (UI vs Game)

Hello, I have a bit strange issues with focus or I think there is some basic functionality missing in UE.

Issue 1:
I need some node like bool IsMouseOnWidget(); because when I click on HUD button my character moves to this location (RTS). How to properly make input ignored when I click on HUD button ?

Issue 2:
After clicking on HUD button, focus is probably changed to “UI only” and I can not use keys to move camera, in order to be able use keys again I need to click on empty place (that probably changes focus back to “UI and Game”.

I don’t think that nodes Set Input Mode UI Only/UI and Game/Game Only are solution here. I tested all of them. Thank you :slight_smile:

I’ve the same problem (probably). Also no solution, but perhaps some of the info here can help you:

Issue 1 solution:

Custom BP node created in C++ (PlayerController class)

.h

UFUNCTION(BlueprintCallable, Category = "Input") 
bool IsMouseOnWidget() const;

.cpp

bool ACOMGamePlayerController::IsMouseOnWidget() const
{
	for (TObjectIterator<UWidget> WidgetItr; WidgetItr; ++WidgetItr)
	{
		if(WidgetItr->IsHovered())
		{
			return true;
		}
	}
	
	return false;
}

Issue 2 solution:

You need to set every UMG widget to bFocusable = false in properties of widget, don’t forget to set it for root too! Best way to debug focus is enabling visual rectangle in Project Settings > User Interface.

could you elaborate on how part 1 works? i’ve tried multiple ways but still can’t get it to work

This code does not work in new versions, here is updated one. Btw. using object iterator is horrible solution, however I have not found better way.

bool UCOMStaticLibrary::IsMouseOnWidget()
{
	// @todo TObjectIterator is not nice
	for (TObjectIterator<UWidget> WidgetItr; WidgetItr; ++WidgetItr)
	{
		TSharedPtr<SWidget> SafeWidget = WidgetItr->GetCachedWidget();

		if (SafeWidget.IsValid() && SafeWidget->IsDirectlyHovered())
		{
			return true;
		}
	}

	return false;
}