I want to draw lines to indicate relationships between actors on screen, for example unit movement paths. I have a User Widget and in OnPaint I’m using ProjectWorldToScreen to get screen space coordinates for the world positions and then Draw Line to draw the actual line. The length and direction of the line I get is correct, but it’s position is off by quite a bit, and the offset varies depending on the size of the render window.
What do I need to do to convert the ProjectWorldToScreen result to a coordinate that can be passed to Draw Line to get a line that start and end right on top of the world position I give to ProjectWorldToScreen? If no possible, what are some other options to accomplish the same thing?
Some images showing my setup, based on the TopDown template, and the result.
Additions to the TopDownCharacter Blueprint class.
I’ve been doing some reading in the UMG part of the documentation, in particular about scaling. The problem is indeed that Project World to Screen and Draw Line uses different screen coordinate systems. We can convert between them by dividing by or multiplying with Get Viewport Scale.
There is also Project World Location to Widget Position which does that for us. I get the line I want when I replace Project World to Screen with Project World Location to Widget Position.