Download

UMG: How to add a button to a exist ui at mouse postion when mouse button is clicked?

Hi,
I want to add some buttons on a exist ui at mouse position when mouse button is clicked.

I have some questions:

  1. How can I know which widget is under the mouse?
    2.Is there mouse click event associated to widget? I seems only found mouse enter and mouse leave event.
    3.How to set the added widget position at runtime?

Another question:
How to create a dragable and resizable ui window?

Thanks!

  1. There’s no global list accessible in Slate/UMG. You need to check IsHovered on the widgets you care about.
  2. Click is currently only implemented on Buttons in slate. So just make whatever you want to be clickable inside a button.
  3. If you added it to the vewport, Set FullScreen Position, if you added it as a child of another widget, there’s a few options; If you added it to a canvas, take the slot property cast it to a canvas panel slot, and adjust the position through the offset. Another option is to adjust the render transform’s translation, which works on any widget, but has different effects because it can extend past the clipping rectangle of the parent widget.

Draggable/resizable UI, you’d need to override the functions for mouse down/mouse move/mouse up on the widget and move the widget accordingly. Re-size same thing, but probably based on some area or handled by another widget that reports the events to the parent.

You may also want to just implement it in Slate and then wrap it as a control you can use in UMG. UMG in 4.5 doesn’t allow for user controls to have later specified content in the designer, so you’d need to hack around it by spawning the content dynamically based on a class property. Depending on how many of these windows you’re making, guessing more than 1, you’ll want it to be reusable.

Thanks, Nick.

Right now what I did is as you said: cast the widget to canvas slot then adjust the layout offset, but if I moved/resized the widget, I need to get it’s new offset/translation to move/resize it. Seems in 4.5 I can’t get widget’s render transform too. So how to based last position to adjust the widget?

You’d need to track it some other way for now, like using a member variable in the owning user widget.

Still can’t figure out how to position a child widget to the mouse position in 4.5…