Hallo nice people! Thank you for reading!
I am scripting the Editor and try to load an Editor Utility Widget (EUW) only by having a string holding the widgets name.
Say I have a string variable with value “EUW_LoadMe”.
The standard Blueprint Node “Create Widget” has an input pin “Class”. So I need a function that checks if an EUW named “EUW_LoadMe” is declared in the project and if so returns a reference to that class.
Since this seems to be possible only with C++ (because Blueprints don’t support reflection), I wrote such a function. But the function fails to find the Widget when it is not has been opened within the Editor for editing or running. Why is that?
It seems, that the Editor gets known of the Widget as soon as it has been opened or run and then does not forget it any more. So when I open the widget “EUW_LoadMe” in the editor or run it, my function succeeds finding the class. Even when the widget is stopped or being closed from editing. When the widget has not been opened before, the function fails.
Now I wonder how I can get a reference to the class “EUW_LoadME” even if the widget has not been opened or run?
Thank you so much! I appreciate your help very, very much!
My function:
TSubclassOf<UUserWidget> UMyBlueprintFunctionLibrary::FindWidgetClassByName(const FString& ComponentName)
{
FString FullComponentName = ComponentName + "_C";
// Try to find the class by name
UClass* FoundClass = FindObject<UClass>(ANY_PACKAGE, *FullComponentName);
if (FoundClass && FoundClass->IsChildOf(UUserWidget::StaticClass())) return FoundClass;
return nullptr;
}