Stuck on this seemingly simple task for 2 days and really need some help...

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:

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:

  1. I’m using UE4.14
  2. My camera has a constraint apsect ratio of 1.77 (16:9)
  3. I didn’t touch any DPI settings
  4. My engine scalability engine is on 100% (Epic)
  5. The same problem also happen in packaged game, PIE, stand alone.

Have you tried Widget Component?

you can add it directly to BP of your NPCs.

Hi BoredEngineer,

Thank you for the quick reply.

I did try using widget component. But although this method gives me a workaround of the problem, the result doesn’t quite match what I am trying to do:

Because the widget component is in 3d space it will be blocked by a 3d object, and I want my target image to behave like a normal UI: always draw on top of 3d objects,

and always maintains the same size no matter the distance.

Thank you again for your suggestion.

Try this option on widget component:

Hi, BoredEngineer!

I apparently overlook that option while I was testing it!

Thank you :slight_smile: