My Widget Hierarchy
–Canvas
----- Vertical Box ( Canvas Slot )
------------ Button1 ( Vertical Box Slot )
------------ Button2 ( Vertical Box Slot ) <- I want to attach left side custom widget “CustomMenu”
…
–CustomMenu ( Canvas Slot )
I want to set dynamic position “customMenu” at “button2” left side… How to get “button2” canvas position ??
[my code]
auto canvasSlot = UWidgetLayoutLibrary::SlotAsCanvasSlot( “Button2” ); <- Cast is null !!!
if (canvasSlot)
{
FVector2D position = canvasSlot->GetPosition();
position.X += canvasSlot->GetSize().X;
UWidgetLayoutLibrary::SlotAsCanvasSlot( “CustomMenu” )->SetPosition(position);
}
Jambax
(Jambax)
2
Button 2 isn’t on the Canvas so that cast will always fail, it’s in a vertical box so it’s slot will be a UVerticalBoxSlot.
Button 2 isn’t on the Canvas so that cast will always fail, it’s in a vertical box so it’s slot will be a UVerticalBoxSlot.
[/QUOTE]
okay…
how to get UVerticalBoxSlot of canvas position??
I want to set canvas position of “CustomMenu”.
Jambax
(Jambax)
4
You can get the vertical box itself, get it’s slot and get that position.
Thank you reply 
I solved using a viewport coordinates.
USlateBlueprintLibrary::AbsoluteToViewport(GetWorld(), “button2”.absolutePosition, screenPosition, viewportPosition);
“customMenu”.SetPositionInViewport(viewportPosition, false);