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:
https://gyazo.com/ee95ce83fe13e5bbb1c17418ea90de4f
set relative pos to anchor:
https://gyazo.com/06f141677ac2fe26f863b8b804acf830
My UMG image setup:
https://gyazo.com/58a472560b2da96280bcf25a37deeeca
Some explanation:
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.
Thank you.
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.