Drawing a Line from mesh to widget component

I am trying to draw a line from a widget that is attached to an actor to its mesh component to make it look like the widget is connected to the actor. I tried overriding the On Paint function using he Project world to Screen/Project World Location to Widget Position nodes in the widget blueprint, but the position of the line is not accurate.

I also tried using the Local to Viewport/Absolute nodes using both Viewport and Player Screen Widget Geometry.

Dividing/Multiplying by Viewport Scale also didn’t work

I’m not really sure how I can convert the world location of the components to a 2d position.

Update on the problem

I am overriding the OnPaint function of the widget component to draw the line.

I figured out that the coordinates in draw line is based on the widget and not the viewport, so I set the starting point to 0,0 to make the line start from the top-left corner of the widget. Tried to add the widget’s desired size to change the start point to the center, but it moved only a little bit. I’m guessing this has something to do with the context pin, but not really sure what I should do with it

Now I have to find the right coordinates for the end point, since the coordinates I get using the Project World Location to Widget Position Node seems like they are viewport coordinates.

My goal is to make a module that can draw lines that connects multiple widgets to its attached actors. If there are any tutorials to do this, please let me know.

Update 2

I had to use the widget component’s current draw size instead of the widget’s desired size.

It works pretty well except when I zoom out, the line won’t be long enough to connect the actor and the widget. I think this is also related to nodes using different geometry. I should try converting the positions using various geometries.

Now I’m trying to write this in C++ so I should look up how to override the OnPaint function in C++.