Announcement

Collapse
No announcement yet.

Get position of UMG Widget

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Get position of UMG Widget

    Hello. I want to draw a line on the screen, by overriding my UIs paint function. The widget-hierarchy looks like this:

    [UI]
    -[Canvas] (filling the whole screen)
    --...
    --...
    --[Border] (anchored to the center of the canvas)

    I want to retrieve the absolute coordinates of the "Border"-widget and start drawing the line from there. I have already tried a million ways but usually the retrieved position is 0, some ways even resulted in a non-zero value that was in relative coordinates (i.e. in the range 0 to 1). But apparently I need absolute coordinates to draw my line. "LocalToAbsolute()" needs some kind of Geometry-parameter that I have never heard of.
    Last edited by tcld; 09-23-2015, 05:09 PM.

    #2
    I tried something new: I created an additional Box (called SizeHelper in the image) that is anchored to the top left corner of the screen and positioned at the lower right corner. Incomprehensibly to me that box does not use relative coordinates, hence its position is dependent on the screen-size. The calculated screen-center (using the shown Blueprint) thus is wrong - but at least it is not in relative coordinates so I could check of the line is actually correctly drawn.


    Does anybody know how to properly draw my line at the center of the screen? How to retrieve absolute (and dynamic) coordinates of widgets?

    Comment


      #3
      The tick event in a Widget Blueprint passes the widget's geometry. You might try seeing if there is a geometry variable or 'Get Geometry' function in your widget.

      Comment


        #4
        Thank you for your input. It didn't help much, though.
        I tried storing the geometry, even though that seems a bit bad performance-wise. As a result I was able to use LocalToAbsolute(), which seemingly would only be useful in a fullscreen application (so it is useless in the editor already). Then I tried LocalToViewport(), which gave me very strange and likely useless results.

        Comment


          #5
          Well, I tried. Maybe look into using the HUD class for drawing? I think there's a draw line function, but without the editor in front of me, I can't be sure.

          Comment


            #6
            There is indeed, I had never noticed that class before. I will take a close look at it, thank you.

            Comment


              #7
              Thank you for for your hint! This class seems to be better suited for custom HUDs, and in particular I can easily draw a simple, stupid line wherever I want.

              Comment


                #8
                Yeah, the HUD class is better suited for world-aware uses. It's terrible at responsive, resizable menus(or anything other than drawing textures to the screen at a hard-coded position) though, that's why we have UMG for UIs.

                Comment

                Working...
                X