Show Widget On Screen

To spawn a widget, your class needs a reference to the Widget Blueprint class.

Use TSubclassOf<T> to create a selectable dropdown in the Unreal Editor, to be able to choose your Widget Blueprint.

[UClass]
public partial class AMyCharacter : ACharacter
{
    [UProperty(PropertyFlags.EditDefaultsOnly)]
    protected partial TSubclassOf<UMyWidget> MyWidgetClass { get; set; }
}

Which creates this in your child BP class, now assign it with a widget blueprint you want to spawn.

Now you can create the widget blueprint and show it:

AddToViewport is the quickest way to get a widget on screen, it’s generally considered "quick and dirty".

I highly recommend using built-in plugins like CommonUI to build more complex and scalable UI. It works with UnrealSharp right out of the box.

Last updated