Download

Button Right Click [Resolved]

Hey,

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

EDIT:

I managed to solve it by overriding NativeOnMouseButtonDown in my custom Inventoryslot UUserWidget class

virtual FReply NativeOnMouseButtonDown(const FGeometry& InGeometry, const FPointerEvent& InMouseEvent) override;

Why not make it so you can handle right click of right object right in OnMouseButtonDown? Maybe create multiple buttons for each inventory slot?

Thank you for your reply but I’m not sure how creating multiple buttons per slot would help me.

I’m trying to handle the right click in OnMouseButtonDown but I’m failing get a reference to the correct item slot object when doing that because of the issues in my first post.

There will be people in the future that will try to have right click functionality in their UMG widgets so I’m sure that this would also help them cause I’m not able to find a solution myself or online

I re-read your post and got that you’re already have a button in each inventory slots, good.
First, you have to set your buttons ClickMethod to Precise Click so that it can distinguish right clicks.
Then you have to use OnMouseButtonDown and check if it’s MouseEvent’s IsMouseButtonDown for RightMouseButton is true (or something similar)