Is it possible to automatically generate UserWidget assets in Script?

We are trying to auto-generate a UserWidget asset from a Json file.

I can create widget instances and uasset files with python script. right underneath


asset_tools = unreal.AssetToolsHelpers.get_asset_tools()
widget_blueprint = asset_tools.create_asset( asset_name=asset_name, package_path="/Game/GenericAssets", asset_class=unreal.WidgetBlueprint, factory=unreal.WidgetBlueprintFactory())

How can I add buttons, text, etc. to this?

I couldn’t find anything about automatic UI generation using scripts.
Please help me.

Just gonna say this is likely going to be a very difficult one, and it won’t be done with python only most likely. It would be an entire engine plugin.

Similar functionality found in this product: https://www.unrealengine.com/marketp…roduct/psd2umg

It auto generates UMG from basically a psd file.

I would love this as well, but again, I don’t think it’s going to be easy. As far as I know there’s no python functionality for creating a specific widget class within a UMG. There’s a lot to consider when doing so. Anchors, Size, Position, Color, Hierarchy, Visibility, and more depending on the widget class.

Thank you for your knowledge.
I’m discouraged to find out how difficult it is.

But I’m glad you shared this with me.
PSD2UMG in Code Plugins - UE Marketplace
This is great. It seems to be helpful.

I decided to create a function for Python in C++
Controlling JSON with Python
Create a widget with C++.

ZFunctions.h



UCLASS()
class MYPROJECT_API UZFunctions : public UBlueprintFunctionLibrary
{
   GENERATED_BODY()
public:
   UFUNCTION(BlueprintCallable)
   static void CalledFromPython(FString InputString);
   UFUNCTION(BlueprintCallable)
   static void AddButton(UWidgetBlueprint *Widget);
};


ZFunction.cpp


void UZFunctions::CalledFromPython(FString InputString)
{
   UE_LOG(LogTemp, Error, TEXT("%s"), *InputString);
}

void UZFunctions::AddButton(UWidgetBlueprint* Widget)
{
   auto WidgetTree = Widget->WidgetTree;
   auto Button = WidgetTree->ConstructWidget<UButton>(UButton::StaticClass(),"hello");
   auto RootCanvas = Cast<UCanvasPanel>(Widget->WidgetTree->RootWidget);
   RootCanvas->AddChild(Button);
}


widget.py


unreal.ZFunctions.add_button(widget)