Click the empty space on the menu triggers mouse click event in other class

Hi, I created a empty level called MainMenuMap,

if I hit the Play button, then I click on those 2 buttons I created, It works as expected,
but when I click the empty space in main menu( a UserWidget spawned in MainMenuMap’s BeginPlay function),

It will trigger the event defined in that BP_Player’s native parent class.

How can I gain a Controller for clicking the buttons on the menu, and don’t trigger the behavior which defined in other Class(like that BP_Player) if I click the empty space?

Try to use UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx. It’s in #include "Blueprint/WidgetBlueprintLibrary.h".

UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(PlayerControllerToSet, WidgetToFocus, MouseLockMode);

But remember, if you want to return a control of your player pawn, use UWidgetBlueprintLibrary::SetInputMode_GameOnly.

UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerControllerToSet);
2 Likes

Add an invisible full-screen backdrop behind your buttons to eat the events.

Thanks, It exactly solved my problem, but here is another question, How do we detect current Controller’s input mode, so we can change its state base the current state?

Thanks, I will give it a try.

I usually manually set input mode on some event, for example opening and closing widget or level changing. I don’t know how to get current input mode.

1 Like