Get Mouse X value on Widget

When using the “Mouse X” in the Third Person Characters, it gives me a value between -1 and 1 accordingly to my mouse moving.

I want to use something similar on my inventory page widget, while I have my inventory open, the problem is, when I open my inventory the value is equal to 0, doesn’t matter how much I move it.

Does anyone know how to get this value?

Override OnMouseMove in the widget - you can get the mouse values there.

The Player Controller has no idea what is happening to the mouse once it’s over a widget - hence 0.

Mine still returns 0, I am calling the player controller → Mouse Delta Seconds, from the Override Mouse Move.

(I accidentally pressed on resolved)

It should be 0. As above, the player controller has no clue what’s up; try this:

The rest is what the widget knows about the pointer.

Thank you, It now gives me a value but its going up to 40, when the maximum should be 1 and the min -1.

Because it’s the delta, the faster you swing the faster it goes. You can Clamp or Map Range for finer control.

The thing is that:

image

Should also give you delta, definitely not -1 <=> 1 range. Are you sure? It does not exceed that range if you spin like a madman?

It worked, thank you!

Now when I click it stops getting the values from the movement. Is there a way to keep getting the values? As I want to rotate my object when it’s clicked and held down.

What are you clicking? A button? Something outside the widget? An unhandled click will be passed back to the player controller and the widget will lose focus. This is intentional but can be intercepted.

As I want to rotate my object when it’s clicked and held down.

Could you explain what that object is? Another widget? It’s hard to imagine what the end goal is. Are we inspecting an item?

1 Like

I am using a Render Target to capture a copy of my character and render it to a Image set as child of an button.

When I click and hold this button I want to make the copy of my character rotate in the same direction of the mouse. I have all the rotation working, my problem now is the dragging.

Could you somehow test it without the button? Almost certain the button would consume mouse move.

Not working, that’s how I set it:

Mouse Move:

And that’s the override when the image is clicked:

And when dragging is true I handle the rotation:

And how are you calling this? We can’t see it above.

my problem now is the dragging.

And what are we dragging? Still a little confused here. Or do you mean just the variable update?

And what are we dragging? Still a little confused here. Or do you mean just the variable update?

It’s just a variable update, that changes the value and apply it as a rotation to the Actor

To handle the rotation

And I am calling it on tick:

I think it’s clear now - you need the mouse delta reported in the widget while the mouse button is held down. You kind of explained it well before, it just did not click with me.

  • ensure the root of the widget is focusable
  • run in UI Only mode (optional but since we’re in the inventory we might as well)

I think it’s clear now - you need the mouse delta reported in the widget while the mouse button is held down.

Do you have any idea how can I do it?

Ensure the root of the widget is focusable.

You do not need more for this to work unless you have native button widgets.

  • onMouseMove:

image

  • onMouseDown:

  • widget root:

image

The above prints for both overrides.


One note: you’re overriding the button down for the image widget (judging by the name):

Try it with the whole widget override instead. Otherwise the image may just handle it and the mouse move will never see it again. But if you do it for the entire widget, the input has nowhere else to go.

Thank you so much, you are a genius!!! I literally spent like 7+ hours on this. It’s working like 99% .

Now I need to check when the left mouse is released so it stops rotating the preview, I guess an override on “On Key Up” would fix.

1 Like

The problem with this method of on MouseButtonDown and Up is when you click on the image and move the mouse away from the widget, then release, it will not detect the onMouseButtonUp event and the Boolean will remain true.
You can use the onMouseLeave event but it’s counter-intuitive a bit.

Any clue how to keep this event even if the mouse left the widget area and released the button?

I tried using a “transparent” button over the whole image and using his events which works perfectly but it consumes the onMouseMove event.

But buttons already work like that…

That’s why you have those:

image

To avoid the default behaviour.


Or do you need this behaviour with non-button widgets?