Add Child doesn't add a userwidget

Hi,

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());
		text->SetText(FText::FromString("test"));

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

			CosmeticsContainer->AddChild(cosmetic);

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

			if (CE_OBJECT_VALID(gridSlot) == true)
			{
				gridSlot->SetColumn(ColumnIndex);
				gridSlot->SetRow(RowIndex);
				gridSlot->SetPadding(FMargin(5.f, 5.f, 5.f, 5.f));
			}

			ColumnIndex++;
		}

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