x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

UMG incorrectly positioning widgets

...that, or the "Viewport Size" node returns incorrect values.

I'm trying to place a lock-on cursor and running into some issues. In the pursuit of debugging the problem, I discovered a really irritating bug: positioning a Canvas slot doesn't ACTUALLY reflect the proper screen size!

See attached pic: alt text

As you can see, I'm PrintString-ing the Viewport X dimension to prove a point: PIE, the dimensions are 1291 x (something). So, for a widget Anchored to the upper-left of the Root Canvas, and with Alignment set to 0.5 x 0.5, this widget SHOULD appear centered over whatever screen dimensions I feed it. Right?

But, see here: I manually feed it a position of 1290. Now, with the reported Viewport size, that should place it halfway off the screen on the right side (with the center of the widget right at the edge of the viewport) Instead, the game just sort of shoves it over. Arbitrarily, it takes an X value of about 1540 to ACTUALLY place the widget on the edge of the screen; this value doesn't seem to be related to anything at all (since not only is it not the viewport's size, but the canvas and game target are 1920x1080, so it's not related to any underlying assumptions about resolution)

I cannot for the life of me figure out why this thing is acting like this. It seems to me that if I feed it screen coordinates, it should appear at those coordinates, but instead it seems to do some sort of arbitrary adjusting of the screen dimensions.

Product Version: Not Selected
Tags:
more ▼

asked Nov 10 '14 at 10:41 PM in Bug Reports

avatar image

RhythmScript
243 20 24 36

avatar image RhythmScript Nov 10 '14 at 10:52 PM

Okay, so not "apropos of nothing" does this happen.

My widget is 256x256. I can get it to move to the right position by taking the viewport size, ADDING 256, and dividing that by the viewport size.

Which means that when UMG places a canvas, it places it along an axis which is defined as "viewport size + widget size". So a 256 px wide widget on a 1920 px wide viewport will be placed at the right edge when placed at 2176, and the left edge at 0.

I can work around this with some simple math but I can't imagine that this behavior is INTENTIONAL

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hello RhythmScript,

I would like to start off by saying that both the node "Set Position" and "Get Viewport Size" are working correctly. This being said, it is due to the fact that the "Set position" node goes off of the canvas panel's size(1920X1080). Whereas the "Get Viewport Size" is going by the resolution of the viewport (which varies depending on your settings). I have an easy mathematical workaround you can use. Please note that this only works if you have your widget anchored is the upper left corner. Canvas Size Divided by Viewport Size and then multiplied by the actual position you would like to end up with. I hope this helps.

Example: alt text

Make it a great day

screenposhelp.png (122.8 kB)
more ▼

answered Nov 11 '14 at 05:18 PM

avatar image

Rudy Q ♦♦ STAFF
47.3k 545 132 525

avatar image RhythmScript Nov 17 '14 at 10:21 PM

Rudy, it doesn't actually work that way. It SHOULD, but it doesn't. See the above post:

Arbitrarily, it takes an X value of about 1540 to ACTUALLY place the widget on the edge of the screen; this value doesn't seem to be related to anything at all (since not only is it not the viewport's size, but the canvas and game target are 1920x1080, so it's not related to any underlying assumptions about resolution)

In order for the math you've supplied to work, you must take the viewport size and ADD the dimensions of the canvas you're moving. Pic related is how I had to set it up and I have no idea why it should be this way. alt text

avatar image Rudy Q ♦♦ STAFF Nov 18 '14 at 02:56 PM

Hello RhythmScript,

I have a couple of quick questions for you. This will help get us on the same page.

Quick questions:

  1. Where do you have your anchor set for the widget that you are trying to place?

  2. When you are running the game did you do so in a stand alone version or did you run it in the viewport?

  3. What exactly are you trying to accomplish with the math I provided? If I have a better understanding of your end goal I may be able to provide a different solution to the issue.

I have a few images that explain how anchor points can also be helpful in placing items on screen. This may be a viable solution depending on your situation.

alt text

alt text

alt text

alt text

alt text

anchorhelp.png (39.4 kB)
anchorhelp2.png (44.0 kB)
anchorhelp3.png (250.7 kB)
anchorhelp4.png (36.8 kB)
anchorhelp5.png (226.7 kB)
avatar image Rudy Q ♦♦ STAFF Nov 18 '14 at 05:17 PM

I have made an alteration to my previous blueprints. This appears to be a more accurate way to position the widgets. I hope this helps.

Note: I am setting the position of the anchor now instead the position of the widget. If you want a more in depth break down of the math feel free to post a comment.

alt text

poshelpupdate.png (188.8 kB)
avatar image fanzypantz Mar 26 '15 at 03:43 PM

what is the canvas x and y variables on that image?

avatar image Rudy Q ♦♦ STAFF Mar 26 '15 at 04:21 PM

Hello fanzypantz,

Canvas x and y are equal to the size of the widgets Canvas panel. Typically these will be equal to 1920x1080 (X= 1920 and Y=1080) I hope this information helps.

avatar image Yulgalminakf Mar 21 '16 at 06:20 AM

Two questions:

  1. Why are you setting the anchor rather than the position?

  2. How do I get the size of the canvas? You said it's "typically" 1920x1080, but how do I actually find that out?

avatar image Rudy Q ♦♦ STAFF Mar 21 '16 at 01:24 PM

Hello Yulgalminakf,

To answer your questions:

  1. I found this method to to be easier to workaround at the time in that version of the engine.

  2. You can change the size of the canvas by setting the Fill Screen drop down to custom and then setting the X and Y sizes. If you would like to get the viewport size during play, you could do this by using get viewport size.

I hope that this information helps.

Make it a great day

avatar image Robinson Company Aug 30 '16 at 11:08 PM

You said that this is a workaround for that version of the engine. Will there be changes to UMG about this topic to make this easier in the future? Say maybe 4.13?

avatar image Rudy Q ♦♦ STAFF Aug 31 '16 at 01:12 PM

Hello Robinson Company,

The comment was in reference to the age of the original post and about how the methods I was using had changed between engine versions due to changes in UMG at the time.

avatar image lufkin Oct 17 '16 at 12:13 AM

Is there a better way to do something like this in newer versions of UMG? I took and adapted your script for my project, and it works only for the Y axis, but always stays at X 0 (so it only moves up and down.) Any idea why?

alt text

capture.jpg (166.9 kB)
avatar image Rudy Q ♦♦ STAFF Oct 17 '16 at 05:16 PM

Hello lufkin

There have been updates since this was posted. I would suggest using "Get mouse position Scaled by DPI" I have provided an example below. I hope that this information helps.

Example:

alt text

Make it a great day

avatar image Stranger Games Sep 16 '16 at 10:58 AM

Hi, your answer looks cool. But I'm not sure how you got the variables Canvas X and Canvas Y. Where did you declare it and how you set its values?

avatar image Rudy Q ♦♦ STAFF Sep 16 '16 at 01:08 PM

Hello Stranger Games,

I just set their default values to 1920 by 1080 (this was the canvas size for my widget). I hope that this information helps.

Make it a great day

avatar image Stranger Games Sep 16 '16 at 02:06 PM

Thanks. However something is still wrong. I think if I did this, I should have the image left upper corner at the middle of the screen, which doesn't happen. FVector2D newSize(1920.0f/2.0f 1920.0f / ViewportSize.X, 1080.0f / 2.0f 1080.0f / ViewportSize.Y); imageSlot->SetPosition(newSize); But thanks anyway!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question