Announcement

Collapse
No announcement yet.

Is it possible to automatically generate UserWidget assets in Script?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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
    Code:
    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.

    #2
    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.
    Systems Design, Project Management, Level Design

    Steam

    Comment


      #3
      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.
      Systems Design, Project Management, Level Design

      Steam

      Comment


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

        But I'm glad you shared this with me.
        https://www.unrealengine.com/marketp...roduct/psd2umg ...
        This is great. It seems to be helpful.

        Comment


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

          ZFunctions.h
          Code:
          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
          Code:
          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
          Code:
          unreal.ZFunctions.add_button(widget)
          Last edited by itouh2; 07-28-2020, 02:18 AM.

          Comment

          Working...
          X