Create/Compose Widgets

Make a class that inherits from UUserWidget (for layouts) or a specific widget like UTextBlock for extensions.

[UClass]
public partial class UMyWidget : UUserWidget
{
}

Now add the child widgets to compose your widget.

The widgets you want to bind needs to have UProperty and BindWidget to work.

[UClass]
public partial class UMyWidget : UUserWidget
{
    [UProperty, BindWidget]
    public partial UImage MyImage { get; set; }
    
    [UProperty, BindWidget]
    public partial UTextBlock MyTextBlock { get; set; }
}

In the Unreal Editor, create a new Widget Blueprint.

When you have opened up the widget asset, you'll see compiler errors stating that the required widgets are missing.

To resolve errors:

  • Drag a widget element you want to bind from the Palette window into your Hierarchy (as shown in the image below)

  • You must rename these spawned widgets to exactly match the property names in your C# code (in this case: MyImage and MyTextBlock).

Hit Compile in the editor. The errors will disappear as the C# properties successfully "bind" to the newly spawned widgets.

Last updated