I’m trying to create a menu with c++ when a player right clicks on a button.
I’ve tried the following:
Use OnHover / OnUnhover to set a pointer to the item while hovering over it and back to nullptr when Unhovering.
The idea is if the pointer is not null and the right mouse button is clicked I could open a menu, simple right?
The problem is that OnUnhover is called before the right mouse button click event happens.
I tried to fix this by checking if the right mouse button is pressed when OnUnhover is called, but IsInputKeyDown(RightMouseButton) returns false when OnUnhover is called by pressing the RMB. I guess this is because only on the next frame it will return true.
This results in my pointer being null by the time my right mouse button event is called.
So i tried overwriting NativeOnMouseEnter and NativeOnMouseLeave, but it results in exactly the same problem.
So I tried another approach;
Storing an array of my inventoryslot widgets, iterating over them when RMB is clicked and create the item specific menu if InventorySlot->IsHovered is true. But IsHovered is never true when doing a right click so that doesn’t work either. I also tried InventorySlot->Button->IsHovered but it also never seems to return true when right clicking.
I also tried editing SButton::OnMouseButtonDown(…) to the code below but this doesn’t cause the delegated OnClicked function to fire on right click
I managed to solve it by overriding NativeOnMouseButtonDown in my custom Inventoryslot UUserWidget class
virtual FReply NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;