Hide show menu, prevent input trigger by PC?

I’m using this to try hide/show my menu.
But it seems the is triggering input after the UI did (they both look for the same key) making the menu show up again…
If I change the UI key it will work fine, I can also hack it kindof by holding down the key for a bit.

This is the code I’m using atm, can someone tell me what I am doing wrong?
Thanks!

// IN UI
FReply UPlayerMenu::NativeOnKeyDown(const FGeometry & InGeometry, const FKeyEvent & InKeyEvent)
{
	
	if (InKeyEvent.GetCharacter() == 'I')
	{
		printc("Close Menu", Blue);
				
		ALPlayerController* PC = (ALPlayerController*)GetWorld()->GetFirstPlayerController();
		PC->TogglePlayerMenu();
		return FReply::Handled();
	}

	return FReply::Unhandled();
}

// IN PC
void ALPlayerController::TogglePlayerMenu()
{
	APlayerHUD* PlayerHUD = (APlayerHUD*)GetHUD();

	if (PlayerHUD->ActiveMenu == EActiveMenu::AE_None)
	{
		printc("Show menu", Cyan);
		PlayerHUD->ShowInventory();
		
	}
	else
	{
		printc("Hide menu", Cyan);
		PlayerHUD->HideInventory();
	}
}

// IN PlayerHUD
void APlayerHUD::ShowInventory()
{
	printc("Drawing PlayerUI", Green);

	if (InventoryMenuClass)
	{
		printc("Show menu", Green);
		
		VisibleUI->AddToViewport();
		ActiveMenu = EActiveMenu::AE_Inventory;
		FInputModeUIOnly Mode;
		Mode.SetWidgetToFocus(VisibleUI->GetCachedWidget());
		GetWorld()->GetFirstPlayerController()->SetInputMode(Mode);
		GetWorld()->GetFirstPlayerController()->bShowMouseCursor = true;
		
	}
}

void APlayerHUD::HideInventory()
{
	if (InventoryMenuClass)
	{
		VisibleUI->RemoveFromViewport();
		ActiveMenu = EActiveMenu::AE_None;

		FInputModeGameOnly GameMode;
		
		GetWorld()->GetFirstPlayerController()->SetInputMode(GameMode);
		GetWorld()->GetFirstPlayerController()->bShowMouseCursor = false;
	}
}

Hey -

Rather than check input in the UI it would be better practice to do this in the player controller. You can setup the action mapping in the project settings with the name of the action and the related key. Then in the Character class you can assign which function to call when the action is taken. The Third Person code template has a good example of this in how the Jump function is setup in the character class.

Cheers

Thanks, I will look into this, I did however fix this problem simply by updating to 4.9.
I somewhere here (forgot where) that there was something strange in the FReply event handling in 4.8, making handled events act like unhandled event sometimes, not clear on how or what.
Tough the update without changing any code did fix the issue for me. Thanks for the help, this does indeed feel like a more logical approach