My problem is simple:
draw a UMG image at NPC’s location on screen space.
My current solution:
convert absolute position to relative position 0~1:
set relative pos to anchor:
My UMG image setup:
Lx = x from ConvertWorldLocationToScreenLocation function
Vx = x from GetViewPortSize function
Sx = UMG image width
relative x = (Lx - Sx * 0.5* Vx / 1920) * 1 / Vx
The Sx * 0.5* Vx / 1920 part, is I want to get the resolution adjusted image size, divided by half, so I can subtract it from the absolute position.
Then I simply divide it by the viewport size to get relative position. (And I did the same thing for y except I substitute 1920 to 1080)
My expectation is that, this calculation should give me the correct position under any viewport size.
But it turns out the result is only correct under 16:9 viewport size, other then that, the position is not correct.
(To be more specific, the x position is correct, but y will be higher then the correct position)
I have looked up on google and noticed there are many developer encounter the same problem as I did(since UE4 4.6), I’ve tried some
of their solutions but to no avail.
If you need more information on this matter, please let me know, any reply will be appreciated.
Some side notes:
- I’m using UE4.14
- My camera has a constraint apsect ratio of 1.77 (16:9)
- I didn’t touch any DPI settings
- My engine scalability engine is on 100% (Epic)
- The same problem also happen in packaged game, PIE, stand alone.