Project world location to widget position Issue

I have a problem with the following code. the widget(red square) is supposed to follow the white cube in the world. but it doesn’t follow it in the right position and when I move the camera around it’s like it changes position it wants to follow. also I clamped it so that it stays in the corner but when its supposed to be on the bottom it teleports to the left top corner.


De2
De3

One possible issue is miss timing.

Some function for widget will run only on the next tick and not current tick.

Like GetDesiredSize:
image
This will run only on the tick to get the actual value.

So it possible you are not getting the correct transformation.

Possible solution

  • Use of Force Layout Pass (this is pretty expensive especially in a tick event)
  • Change method, like using a cube bp attached with a widget component.

Ok so I moved the code over to the cube bp instead of the widget bp and now the location is correct. thank you for the suggestion.
but the problem with the clamp is still there. when the widget is on the edges of the screen it works fine except the bottom edge of the screen. when it is on the edge of the bottom it teleports to the top left corner as it resets it’s position to zero. the red square is placed on the top left corner in the bp if that helps.

EDIT: the red square is on the cube in the start but when I look away it goes back to the wrong place. :cry:

EDIT2: so I changed the set position in viewport to set render translation and it centers on the object perfectly but the problem now is that when I look away espacially when the object is bellow the camera and outside the view it sets back to zero as I tested in print.

im pretty sure set position in viewport is broken, i used it before for damage numbers and an update killed it

heres another link

If you add the ForceLayoutPass just before the SetPositionInViewport change anything ?