Buttons seem to override my input?

I am currently using buttons as the slots in my inventory, mostly due to the practical “OnHovered” and “OnUnhovered” events.

However, while using the Enhanced Input System, clicking (with LMB) only fires when I am NOT also pressing one of these slots (buttons). I could imagine that is intentional, but is there any way to override it?

This happens no matter what kind of user widget I create, and is also the case for the bool function “IsHovered” and the events “OnMouseEnter” and “OnMouseLeave”.

No matter what I seem to do, when LMB or RMB is clicked or held, “OnMouseLeave” is called or “IsHovered” is set to false… Is there really no way in the whole of Unreal Engine 5 that lets me disable these strange behaviours? I understand how it could be useful in some cases, but right now it’s seriously obstructing my work, and I have no idea how I would go about creating similar functions without taking a massive performance hit or unnecessary amounts of extra work…

I would appreciate if anyone else has encountered the same, and especially if there are known workarounds for this!

i think your problem is the mouseclick isnt ‘Handled’ and so goes through to the world which causes the mouse to leave the widget, try overriding OnMouseButtonDown and return handled

1 Like

Thank you so much! Thanks to your input I just figured out that I could ward off the problem by setting the “Viewport Mouse Capture Mode” to “Do not capture”. Problem is, now my enhanced input action using the mouse buttons won’t fire anymore… Unless I double click?? I really have no idea what’s going on…

Back to your solution though, how do you suggest I go about doing that? I am still relatively new to the engine and I have absolutely no idea how to "Override OnMouseButtonDown and return handled” or really what it even means.

I really don’t understand why Unreal won’t let me use the mouse buttons the same way I use the keyboard keys! It makes it incredibly frustrating to implement essential game mechanics with rebindable keys, when I have to make these strange exceptions and workarounds for all bindings that use mouse buttons! Is there any simple way to disable all the strange extra functions built-in to Unreal, and simply use them as I would keyboard keys?

I struggle to understand this engine, and really appreciate the help! “:D”

what kind of game are you making?

i mentioned above try overriding OnMouseButtonDown, but depending on your game you can also try changing the InputMode to UIOnly.

you can search for these keywords in engine.

1 Like

this is in the widget, look at the override functions for OnMouseButtonDown and drag off the handled pin and type in handled

1 Like

What I’m currently working on is the inventory for a survival game I’m working on, hence the need to register which slots are being hovered and not (when moving items from slot to slot).

It could seem my main problem is that I don’t use the “OnMouseButton” events, but the Enhanced Input System. Setting the input mode to UIOnly works so that LMB and RMB don’t disrupt the “IsHovered” function, but it also removes the ability to use any of the buttons I’ve bound in my Enhanced Input Mapping Context…

And regarding the “OnMouseButtonDown” function you’re referring to, how do I find it? Is it something I need to do in C++, because I can’t find it in my widget blueprint even when searching in the blueprint…

Thanks again for your patience!

1 Like

Thank you! Now it registers the IsHovered events without being interrupted by mouse clicks! HOWEVER, now it simply consumes the mouse clicks completely! Why is that? The Enhanced Input Events are called when I press literally anywhere else than on the UI elements, where even in debug it is not registered as triggered.

yep thats what handled means, its saying the UI handled the click so input can be ignored. this is usually what youd want. however you can put logic before the Handled Event, so for instance you can manually call your input event.

i know that seems really round about but the idea is say if LeftClick was meant to fire a weapon you dont want that when you click on an inventory widget, unless you do in which case call it manually :slight_smile:

1 Like

■■■■… thank you for your great answers though! It’s been really helpful in understanding this system a little better :smiley:
I realise that using any kind of IsHovered, OnMouseEnter, etc. might simply not work out for the use cases I have in mind…

I have tried checking if the mouse is within the bounds of the geometry of a widget using another approach. I found a node I thought would work well, and it ■■■■ sure did until I scaled the game window :sweat_smile:

Could you maybe try to explain what this node really is asking about?

I really cannot wrap my head around this “Absolute Coordinate”, or how to visualise it in my head or on paper… Do you have knowledge of this?

GetMousePosition returns these coordinates, and I have absolutely no clue how to convert it to absolute coordinates, or even what that is.

I hope I’m not causing you too much of a headache with all of these questions, I made the switch from Unity only a couple months ago and it’s really a struggle to understand these things in a completely different way.

tell me more about this, i could be able to help rather than trying to reinvent the wheel

you can get the viewport/widget scale and use math but i dont think this method is worth it when you already have OnHovered events

1 Like

Fair point. I think the biggest trouble I come across here is the wish to have custom keybindings, and considering everything works perfectly fine with any key not on the mouse, it seems so counterintuitive to do all this extra work just to make sure it works for the mouse buttons… I am left handed myself, and having the ability to switch around keys and buttons for more ambidextrous gamers is an important factor for me, and so using the “MouseEvent → GetKey == LMB/RMB” simply isn’t going to cut it here…

I believe we made some real progress by handling the OnMouseButtonDown event though! If only I could then do something like MouseEvent → GetKey == InputAction “ActionButton”.GetKey or something like that, it would all solve the problem immediately… But for some reason I cannot get the bound keys of an Enhanced Input Action :face_exhaling:

i havent used it myself but you could look into CommonUI, i think thats the point of it.

otherwise its not too hard, create a border override the functions then use that widget as a parent for all ‘buttons’ and you only have to do it once and in one place

1 Like

I tried to use borders, but they have the exact same problem as buttons, being interrupted by the mouse buttons being pressed. Same for all of CommonUI. I’ve tried to use every single built-in alternative there is, but there seems to be no way on earth to use OnHovered functions together with the right mouse button…

you definitely can, i’m doing it in my game. I’m just not sure what to suggest because im not sure exactly how yours works.

but for simplicity, you have an IA calling a function (lets call that function left click)

in the MouseButtonOverride get OwningPlayer→CastToYourPlayer→CallLeftClick

1 Like

I know it’s been a couple days now, but after getting side-tracked a couple of times working on other aspects of the game, I went back to this whole inventory thing and tried your solution again, and it worked!

I now simply override the OnMouseButton events and check which of the InputAction Mappings is equal to the GetEffectingButton variable! It works as well as I’d hoped, and though it took more work than I thought would be necessary when starting out this thread, it works now all thanks to you!

Thank you for your patience and kindness when explaining these concepts to an Unreal beginner! You’ve really made my day, and I wish you a great day too :grinning_face_with_smiling_eyes:

1 Like

no worries, glad you got it working

1 Like