How to position a widget in the viewport and keep it responsive without a canvas panel?

helo, i’m trying to create a context menu and an item inspector for my inventory, both should appear next to the slot and in both i’m not using a canvas panel. The way that i’m doing is: i’m getting the slot position and passing it to the HUD, which then passes it to these widgets to set their positions. However, it’s not working, and it’s not responsive: if I reduce the screen size, the widget moves extremely far away.

in full screen:

in widow mode:

here how i get my slot position in the slot widget:

FVector2D UInv_ItemSlot::GetSlotPosition() const
{
FGeometry Geometry = GetCachedGeometry();
FVector2D WidgetCenter = Geometry.GetLocalPositionAtCoordinates(FVector2D(0.5f, 0.5f));
FVector2D PixelPosition;
FVector2D ViewportPosition;
USlateBlueprintLibrary::LocalToViewport(GetWorld(), Geometry, WidgetCenter, PixelPosition, ViewportPosition);
UWidgetLayoutLibrary::GetViewportScale(this);
return PixelPosition;
}

and i get the slot position in my inspector and context menu and do this:

SetPositionInViewport(SlotPosition, false);

i already tested using false to bRemoveDPIScale, but nothing has changed

here my widget setup in editor:

i’m using a scale box to override the size, and it’s set to desire on screen with a value of 0.5 in pivot

Hello @riukuh ,
You could try adding the canvas panel and adjusting the anchors properly.

Canvas Panel

Anchor-Points

Let me know if it works!

1 Like

i’m trying to do it without canvas panel, there’s a way to do it without a canvas?

i don’t think so. as it’s the canvas that provides some of those features.

you could implement your own logic for updating the layout, i think there’s a virtual function for that. but it sounds extremely convoluted. i don’t understand your restriction of not using a canvas.

1 Like