I am not sure this can be answered without knowing some more about your widget. But you should bear in mind that UMG-designer does some layout stuff automatically when placing items, that you might have to do explictly in code/bluepints (i.e taking the slot after you add a child, and setting properties).
Did you solve this? I’m seeing the same issue. I suspect I am missing something important about how layouts are calculated, and that I need a special canvas as root along with proper anchors etc, but I just can’t figure it out…
My “child” has the size 64x64 in its own Widget-file (an image) (even tried with a SizeBox as root, with overridden 64x64 size), but when I add it to the parent using ->AddChild() it shows up as 100x30 or something. I’ve tried all combinations of anchors and SizeToContent etc I can think of, but it’s just plain wrong.
I’m not sure if it’s possible to add a child widget to primitives (such as UBorder, UButton and etc) with it’s own size, but for canvas panel you can use UCanvasPanelSlot* UCanvasPanel::AddChildToCanvas(UWidget* Content) and after that use void UCanvasPanelSlot::SetSize(FVector2D InSize).
For example:
auto NewSpotRaw = WidgetTree->ConstructWidget<UUserWidgetChild>(UUserWidgetChild::StaticClass()); // create child of UUserWidget
UCanvasPanelSlot* NewSlot = CanvasPanel->AddChildToCanvas(NewSpotRaw); // add child to canvas panel and save new slot to variable
NewSlot->SetAlignment({ 0.5f, 0.5f }); // set some settings (pivot of new slot)
NewSlot->SetPosition(FVector2d(250.0f)); // set another some settings (position on screen)
NewSlot->SetSize({ 30.0f, 30.0f }); // set size 30x30