[UE5.1.1, Bug report] UserWidget::SetPositionInViewport broken.

  1. Calling SetPositionInViewport with coordinates outside the viewport on tick breaks tick.
  2. Calling SetPositionInViewport appears to accept only coordinates relative to the viewport (FVector2D(100.f,100.f) shows top left with an offset), but when converting absolute to local coordinates using the viewport geometry we end up with wrong coordinates
// FVector2D Coordinates;
Coordinates = UWidgetLayoutLibrary::GetPlayerScreenWidgetGeometry(GetOwningPlayer()).AbsoluteToLocal(Coordinates);
SetPositionInViewport(Coordinates);

Whatever is going on there is a pain to debug since a wrong coordinate appears to break the engine in half. I also read reports that SetPositionInViewport did not work at all in UE5.1. Well… Great

1 Like

Yes, there is something weird happening with it. I made a widget appear in a specific place in the viewport, and it works on my machine, but the same code on my coworker’s computer always places the widget in the top left corner, and I have no idea why.

1 Like

Currently I am using a canvas slot again to make it work, it is awkward.

CanvasSlot->SetPosition(LocalPosition);

You must be very careful with SetPositionInViewport and (I think) canvas slots as well to clamp coordinates within the available geometry. If you do this wrong during tick, tick just stops.

1 Like

Yes, I experienced it as well. I had to fall back to adding widgets to a canvas panel instead of to the screen even though scaling can mess up the visuals a bit, but at least the positioning works.

And you’re right about the ticks too. When not rendered, the widget stops ticking, either because it’s off-screen or its visibility is Hidden or Collapsed. Sometimes you have to use the tick function of the external widget to trigger the functionality of the hidden one.

1 Like

That’s odd when you think about it. Tick is about the least I’d worry about if it runs without any heavy custom code attached to it. Odd, because I have not been able to detect an accurate “on screen” situation any way with widgets… Either by visibility or for example clipped in a scroll box:

[UE5.1, Bug Report] Widget's IsVisible is funny.

Also odd because a hidden / removed widget does still use tons of other resources and events that I do worry about:

[Bug report] Bad widget performance : Slate : ProcessMouseMove

Man the list keeps getting longer :slight_smile: