I don't know why this code doesn't work.

Hi. I am working on transferring the Blueprint to CPP about UserWidget.
However, I continued to experience problems while using AddToViewPort(), so I asked a question.

It’s my BP about AddToViewPort.

for (int i = 0; i < 5; i++)
{
	FST_InventoryCPP NewEmptyInventoryItem;

	Inventory.Add(NewEmptyInventoryItem);	
}	

TArray<UUserWidget*> FoundWidgets;
UWidgetBlueprintLibrary::GetAllWidgetsOfClass(GetWorld(), FoundWidgets, UBM_InventoryContainer::StaticClass(), false);

for (UUserWidget* Widget : FoundWidgets)
{
	UBM_InventoryContainer* InventoryContainerWidget = Cast<UBM_InventoryContainer>(Widget);
	if (InventoryContainerWidget)
	{
		
		UBM_InventoryContainer* newInv = CreateWidget<UBM_InventoryContainer>(GetWorld(), UBM_InventoryContainer::StaticClass());
		newInv->AddToViewport();
		UE_LOG(LogTemp, Warning, TEXT("Is IT GOOD?"));
	}
}

It’s my CPP code and It’s BeginPlay() func.

I set my custom widget’s visbiliy to visible too.

In blueprint you’re using the ‘Is Not Valid’ branch, but if (InventoryContainerWidget) isn’t the C++ equivalent of that. You’d want if (!InventoryContainerWidget) or if(InventoryContainerWidget == nullptr).

Oh, there was a part I missed. Thank you for answer!