I’ve looked into the UBlueprintWidget class and WidgetBlueprintEditorUtils, but couldn’t find a way to select a widget in the UMG Editor (either widgettree or designer space) programmatically. Is there a specific method or approach to accomplish this?
Ok, I've found the solution. Mb someone else will need it in the future, so here it is:
if (GEditor) {
if (UAssetEditorSubsystem* AssetEditorSubsystem = GEditor-GetEditorSubsystem<UAssetEditorSubsystem>()) {
if (IAssetEditorInstance* AssetEdtiorInstance = AssetEditorSubsystem-FindEditorForAsset(_WidgetBlueprint, true)) {
if (FWidgetBlueprintEditor* WidgetBlueprintEditor = StaticCast<FWidgetBlueprintEditor*>(AssetEdtiorInstance)) {
FWidgetReference SelectedWidgetReference = WidgetBlueprintEditor-GetReferenceFromPreview(SelectedWidget);
if (SelectedWidgetReference.IsValid()) {
TSet<FWidgetReference> SetForReference;
SetForReference.Add(SelectedWidgetReference);
ParentWidgetBlueprintEditor->SelectWidgets(SetForReference, true);
}
}
}
oh and selected widget is UWidgetBlueprint, to get it from simple UWidget u can use #include "Editor/UMGEditor/Public/WidgetBlueprintEditorUtils.h", theres a function for it
static UWidgetBlueprint* GetWidgetBlueprintFromWidget(const UWidget* Widget);