Get Widget Geometry On Construct Event

I have User Widget Added to Viewport that the User can Drag in Viewport.

When clicked, the Widget is draggable (Uses Tick), and sets the Widget Position in Viewport to Mouse Position in Viewport.

I have a variable “MouseOffset” that is set on Widget Button Pressed, and uses the Tick Space Geometry to get the geometry of the widget to subtract it from the Mouse Position in Viewport and store this value. This is so that on tick, I can use this offset to properly set the Widget Position in Viewport to prevent the Widget from “Popping” to the Mouse Position.

This is working great, except the first time the Widget Button is Pressed, it pops to the Viewport (0,0) Position, and then after that works as expected. I assume this is because I am setting the MouseOffset on Widget Button Down event with Tick Space Geometry (Cached Geometry does same) and there are no valus et for the Widget Geometry at that point?

I can print string the Local to Viewport value of the Geometry On Pressed, and the first press on widget, prints X=0 Y=0; then after release and a 2nd pressed event on widget, the print string will return a proper value?

I tried setting a Variable “Geometry” On Construct Event using a Delay(0.0) Node to get the value in the next tick after On Construct, and then use a Do Once Node, to use that value the first time, however, this did not work.

If I set delay to 0.04 I can get a result that is in viewport (0,0)


The red Dot in corner is a DebugWidget created when panel is created and its position in viewport set as shown in above code image

How can I prevent the Dragggable Widget from Popping to this location on the first Button Down if I cannot get Proper Geometry for the Widget?

I was able to get this to work setting widget position in viewport on the On Construct Event using a delay of 0.05. Add to Viewport places widget automatically in center of viewport, but I had to add code to calculate and set the position of the Widget in the middle of the viewport.

Seems odd, because it seems I am re-writing and re-executing code that is already being executed under the hood?



There is a node called Force Layout Prepass that’d help here, I think - have a look. Also, consider binding onInitialised instead.

Oh, thank you for the reminder, I completely forgot about Force Pre-pass!

I will have to try this, as it would be much better than hiding the widget, moving, re-setting visibility all with a delay.

I am guessing by setting a new position for widget I am essentially forcing the widget to be redrawn and updating the geometry.

EDIT: I tried putting Force Layout Pre-Pass On Initialized, but that did not work, widget would still pop first time it is clicked and calculating the Mouse Position Offset.

I also tried putting Force Layout Pre-Pass as the first thing done when the Panel Header Button (for Dragging) is Pressed, and it would still pop.

I had to go back to setting the Widget Blueprint as Hidden (Not Collapsed, so it has layout information), and then doing the delay, set position and set visibility to get it to work :frowning: I though for sure Force Prepass would work…

That should go as the last thing in Construct, instead of your funky rejiggle function. Event binding goes into init.

Yeah, it was the last thing. My funnky jiggle code was last thing, I disconnected it and replaced it with the Force Layout Prepass. I also tried removing my funcky code and putting force prepass on initialized, and also tried putting it as first thing to execute On Button Pressed.

You know for sure this should solve my problem and I need to keep trying/debugging to figure out why it is not working in my code?

You referring to the On Get User Settings Event Bind I am doing on Construct?
It works being in the Construct Event, I can certainly put On Initialized, but I am curious as to why there instead of On Construct? I like to know the reasons for things so I can understand better and remember and learn better.

Greatly appreciate the feedback. Thank You!

This is the current Construct code that works, the whole funcky position code was replaced with Force Layout Prepass

Tried this, and you can see the Print String for the Local to Viewport Position value, but widget stills “pops” to upper Left (0,0) corner when on the first On Pressed



Note the Negative Values for the Local to Viewport Position

EDIT: Tried using a delay before Forceing Prepass and still did not work

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.