How to have a right click event on a HUD button?

Hey all working on some inventory stuff and I want the player to be able to right click on items in the inventory to see options of what they can do with it.

I can do it fine with left click but I want left click to be the control for a different function, however it doesn’t seem like it’s possible to do a on right click event for buttons, I can do a Is mouse button down with a true/false but since it’s not a pointer event I can’t plug an input into it.

So how do you do a right click event for HUD buttons?

Any help appreciated thanks

How would this work if the button is part of a larger hud though,? How would calling on mouse button down work for multiple inventory buttons?

Well the player can only add a finite amount of items to inventory so they are just set to hidden and then when an item is added to the inventory the first one is unhidden, then the next etc, etc…

Just the defaults though I can try making a custom button hud tonight after work, no idea how tog o about that but I’m sure it’s not that hard and there’s probably plenty of tuts anyways, so good start tbh, thanks

You need to create your custom button widget (if you haven’t already). There you override OnMouseButtonDownFunction like so:

But if you just want to display info you can do it with OnHovered

3 Likes

It would work the same way as OnClicked, OnPressed etc. It’s up to you to update the “options” text whenever the button is clicked. But as I said you need to create your custom button widget. The call Right Click is and event dispatcher that you can bind and assign to.

More info is needed about your buttons. I assume they are dynamically created and added to your HUD, right?

1 Like

You just create a new widget BP and in there place a button and override OnMouseButtonDown like in the picture (style it however you want). Then in your main widget use that button instead of the default button.

1 Like

I know this is old but I finally got to this I ended up working on other misc. projects lmao. And I got it setup correctly but it seems I can’t actually edit how the button looks or it’s functions?

That is only if it’s part of a larger hud. If I just go into the custom widget bp I can edit it however I like but that means I’d have to create a new right click button widget for every single button in my project.

I have a advanced inventory system i am building and my left and right clicks do two different codes so it can be done would just need to know more about what you wanna do you can always make the each mouse button right click different depending on the button your in anyone needing help can email me at imstilldabs@gmail.com for a faster reply.or more in-depth help.

You can expose what ever you want to be modified, for example, the color. Inside your button widget create a color variable and make it Public. Then on Event Pre-construct set the color of the button to use the color from the variable. Then in your HUD widget you can modify the color of the button. In the image I’ve attached it’s the same button but with different colors, text and behavior.

305292-buttons.png

1 Like

I’m attempting to have a button on screen to select an object with left click and bring up a new border if the selected object is right clicked… So far everything is set up and working except for the right click. I don’t fully understand how to call on this event dispatcher after I put my custom button into my GamePlay UMG. How do I use this new custom button in a different UMG and have the ability to either right click or left click it to call two different events or functions? I’m not too familiar with event dispatchers yet so I’m sorry if this seems like a dumb question.

Edit: Never mind… It appears that as soon as I place the custom button into my widget and make it a variable) I get the option to use “Call Right Click” :slight_smile:

Let’s say this is the button, here it’s made out of a simple border, overriding onButtonDown:

We click the border, figure out whether it was the left button and call the dispatcher.

That’d depend on what / where that different UMG is. However, if you simply add this custom button to a widget, you can flag it as a variable and the dispatcher’s delegate will be available immediately:

image


If the listening widget is unrelated to the one with the button that broadcasts the click, you’ll need to bind the event dynamically. If you need a more concrete example, you’d need to explain the dependency between the widgets that need to communicate.

Thank you for the quick response! I was confusing myself by looking at the button events in the custom button’s button (Wow that was a mouth full). After adding the new custom button to my main UMG (and ticking the “is variable”) the event appears and is hopefully usable the way that I intend it to be. You are awesome and I appreciate you! :slight_smile:

1 Like

One more quick question… How would I go about adding a shift click option? I’ve tried a few ways to no avail…

• ensure the widget is keyboard focusable and give it keyboard focus so it can detect keys going down
• override onKeyDown => check which key => set a new ShiftIsDown bool true (or false if key is undesired)
• when RMB goes down, query the abovementioned flag