Click button AND drag image?

Hi,

I’m trying to create the standard featureset for skill bars in RPGs where if you click on the skill it triggers, but if you drag the skill you can switch two around.

This was working fine at some point then eventually it ended up breaking (once upgrading to UE5). Here’s my layout:

image

SkillButton has a click event:

This works just fine. The issue starts happening when I use OnMouseButtonDown for the parent, W_Skill. I need to use OnMouseButtonDown to detect a drag. I have other drag/drop operations on the widget. However, this event never gets fired because the button consumes the event. As soon as I remove Click from the button, drag/drop starts working.

I was reading a couple of threads and they mentioned I should switch to OnPreviewMouseButtonDown, and that’s what I’ve done, but now I have to double click to get Click to fire. Drag and drop is working tho.

Does anyone have any idea how to fix this?

Does anyone have any idea how to fix this?

All you say adds up, buttons consume input very hungrily and rob you of granular control - input handling. OnPreviewMouseButtonDown may work but may as well open another can of worms. Imho, not worth it.

The solution is not to use the native buttons - I’d like to say at all but, at least, avoid them for drag & drop ops. Make your own button instead - create a widget with a border, add the necessarily functionality and use it in place of native buttons.

This approach also comes with a ton of side benefits. For example, lets say we’d like to change the buttons’ looks throughout the game - I’d hate to revisit 143 (sub)widgets in 10 menus and manually update all them buttons… (and I do know about styling).

But since we’ve been using a wrapper for a border, we need to do it only once and the amend will propagate. And you can then take advantage of inheritance, which is pretty much a must for anything beyond the most simple menu.

Don’t even get me started on right clicking a button, clicking through a button and forcing a release… Buttons are tempting because they’re set up nicely, with events, sounds, hover states. But that makes them very inflexible at the same time.


tl;dr: native buttons are an evil trap if you ever want to use them for things other than simple clicks

1 Like

Fantastic response. Let me do some moving around here and I’ll mark your answer as the solution once I get this all working.

1 Like

Apparently this post is not a question so I can’t mark your answer as the solution but this is exactly right and it started working almost immediately after your post. THANK YOU.

1 Like