Hello @Antidamage I actually was doing the same 2 weeks ago. I wrote this example: lets asume you want to create a new SWindow and use a UMG widget inside of it:
void CreateWindowFromUMG(UWidgetBlueprint* Blueprint)
{
if (!Blueprint) return;
//~ Gets actual widget class from the blueprint
TSubclassOf<UEditorUtilityWidget> WidgetClass = Blueprint->GeneratedClass;
//~ We need da world
UWorld* World = GEditor->GetEditorWorldContext().World();
check(World);
//~ Create widget
UEditorUtilityWidget* CreatedUMGWidget = CreateWidget<UEditorUtilityWidget>(World, WidgetClass);
if (CreatedUMGWidget)
{
//~ Create Slate window
TSharedPtr<SWindow> EditorTab = SNew(SWindow)
.AutoCenter(EAutoCenter::None)
.Title(FText::FromString("my win"))
.IsInitiallyMaximized(false)
.ClientSize(FVector2D(300,300))
.SizingRule(ESizingRule::UserSized)
.SupportsMaximize(true)
.SupportsMinimize(true)
.CreateTitleBar(true)
.HasCloseButton(true);
//~ Add Windows to slate app
FSlateApplication & SlateApp = FSlateApplication::Get();
SlateApp.AddWindow(EditorTab.ToSharedRef(), true);
//~ Use UMG in slate
EditorTab->SetContent(CreatedUMGWidget->TakeWidget());
}
}
if you want to use the path to your asset like in your example, I suggest you to use FAssetData instead, it is easier.
Cheers!
I couldn’t get LoadBlueprintAssetDataFromPath() to find anything in the path, which was odd, so I tried FindObject instead and it worked.
From here the following happened:
Trying to instantiate the UI in the tab results in “Ensure(InWidgetTree)” failing to pass during CreateWidget.
Recompiling the blueprint crashes due to a cast failing: CastLogError()
Reload, duplicate blueprint, delete old blueprint, rename new blueprint to the same. Show tab. It works.
Reload, back to 1.
I would just assume that it’s not being instantiated or loaded properly, but then the blueprint is corrupted on reload, yet is somehow still OK when duplicated replacing the old one.