Is it posible to move a widget inside an UserWidget via code?

I’m trying to make something quite simple, yet i can’t find any way to do so…
I want to be able to move the position of an UButton inside of my UserWidget in runtime via code.
Like, for example: I have my button in X(200)Y(200) and when I press another diferrent button (or the same, whatever) the SAME button moves to X(300)Y(300).
I can’t have two diferent buttons and make 1 visible and the other hidden cause I need to keep the OnClick event the same.
I’ve read the UButton doccumentation and there doesn’t even seems to exist a variable “position” or something like that.
The further I could get was this:

There is this variable called Slot which I guess is the position of the widget inside of the UserWidget (wild guess tbh), but I have no idea how to handle it.
I would like to make this in C++ but I dont even know how to do it in Blueprint so any kind of help would be apreciated (^_^)
Thanks in advance.

I’m still loking for the way to do this in C++ however I found the answer for blueprint method here: Dynamically set widget position on canvas panel?
I’ll post a picture of the blueprints nodes in case someone needs it, this nodes take the existing button (Button_165) and every time it’s clicked, move its own position to (x+100,y)

#include "Components/Widget.h"
#include "Components/CanvasPanelSlot.h"

//UWidget* Widget;
auto Slot = Cast<UCanvasPanelSlot>(Widget->Slot);
Slot->SetPosition(Slot->GetPosition() + FVector2D(100, 0));

I guess I understood everything, thank you for your comment.
But when I used it on my code like: (Respuesta1 is the button i want to move)

auto Slot = Cast<UCanvasPanelSlot>(Respuesta1->Slot);
Slot->SetPosition(Slot->GetPosition() + FVector2D(100, 0));

I get this error log:

I have no idea what “auto” does, for what I’ve could find is like an automatic variable type but I might be wrong.

None of that is necessary.
Use widget animation feature of UMG.

1 Like

It’s just that the variable name “Slot” is already taken by your current class probably, name it something else.
auto simply tells the compiler to infer the type based on context, in this case UCanvasPanelSlot*.

UCanvasPanelSlot* TheSlot = Cast<UCanvasPanelSlot>(Respuesta1->Slot);
TheSlot->SetPosition(TheSlot->GetPosition() + FVector2D(100, 0));