Add Child doesn't add a userwidget


I’m trying to add a custom user widget that only has an overlay and an image in it as a child to a grid panel. Debugging through I can see it successfully creates the widget but on the viewport it’s not visible. However when I use WidgetTree->ConstructObject(UTextBlock::StaticClass()); it works fine. Also using blueprint to create widget and add it as a child works fine.

UCeCosmeticItem* cosmetic = CreateWidget<UCeCosmeticItem>(GetOwningPlayer(), UCeCosmeticItem::StaticClass());
		UTextBlock* text = WidgetTree->ConstructWidget<UTextBlock>(UTextBlock::StaticClass());

		if (CE_OBJECT_VALID(cosmetic) == true)
			//Container->AddChildToGrid(cosmetic, RowIndex, ColumnIndex);


			UGridSlot* gridSlot = Cast<UGridSlot>(cosmetic->Slot);

			if (CE_OBJECT_VALID(gridSlot) == true)
				gridSlot->SetPadding(FMargin(5.f, 5.f, 5.f, 5.f));


Figured out the issue, I needed a UPROPERTY() TSubClassOf pointer to the blueprint instance of the class and pass that in, instead of using UCeCosmeticItem::StaticClass

1 Like