How to create UUserWidget and populate it with widgets in C++?
For example, create UUserWidget, then create and add Text Box to it
I’ve tried to WidgetTree->CosntructWidget and assigning it to WidgetTree->RootWidget inside NativeOnInitialized/NativeConstruct/NativePreConstruct, like so:
I remember trying to do this a while back and gave up. The only thing I’ve seen since is trying to tell the editor that the widget hierarchy has been modified. You’ll need to call Modify() on every asset you’ve added and every parent in the hierarchy.
UWidgetBlueprintGeneratedClass* wbpClass = Cast<UWidgetBlueprintGeneratedClass>(WidgetTree->RootWidget->GetClass());
UWidgetBlueprint* asset = Cast<UWidgetBlueprint>(wbpClass->GetPackage()->FindAssetInPackage());
asset->Modify();
// Tell editor that blueprint has changed.
FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(asset);
I have no clue if this will work but thought I’d mention it as it’s easy enough to try.
I won’t lie, I should have checked that thread before suggesting it, as it doesn’t even have a proper answer to the OP’s problem. I just saw a post with 13 likes and was convinced it should work.
I found a site that seems to do what you’re asking. I tested it myself, and it seems to work (sort of).