Unreal Engine 5 · Blueprint → C++
Create Widget in Unreal Engine 5 C++
The Create Widget Blueprint node maps to the templated CreateWidget<UUserWidget>(GetWorld(), WidgetClass) factory function in C++, which instantiates a UMG widget from a TSubclassOf<UUserWidget> class reference.
Blueprint node & C++ equivalent

private:
// The specific user widget needs to be set in blueprint
UPROPERTY(EditAnywhere, meta = (AllowPrivateAccess = "true"))
TSubclassOf<UUserWidget> ExampleWidgetClass;#include "Blueprint/UserWidget.h"
if (ExampleWidgetClass)
{
// Create widget
UUserWidget* ExampleWidget = CreateWidget<UUserWidget>(GetWorld(), ExampleWidgetClass);
}What does the Create Widget node do?
Create Widget instantiates a UMG user widget from a widget class so you can later display it on screen. In Blueprint you pick the widget class and a player; in C++ you call the global CreateWidget template function declared in Blueprint/UserWidget.h.
It only constructs the widget object in memory. The widget will not appear until you add it to the viewport or to a parent widget.
The C++ equivalent
Expose the class to set in the editor with a UPROPERTY(EditAnywhere) of type TSubclassOf<UUserWidget>, then call CreateWidget<UUserWidget>(GetWorld(), ExampleWidgetClass). The template argument controls the return type, so use your own subclass (for example CreateWidget<UMyWidget>) when you need access to custom members.
Always null-check the class pointer before calling, because an unset TSubclassOf will produce no widget. The first argument is a world context (here GetWorld()); you can also pass an APlayerController* to bind the widget to a specific player.
Common mistakes
Forgetting to include Blueprint/UserWidget.h will cause CreateWidget and UUserWidget to fail to compile. Another frequent error is expecting the widget to show immediately. CreateWidget alone does nothing visible until you call AddToViewport().
Do not hard-code the widget class in C++ with StaticClass() unless intended. Using TSubclassOf and EditAnywhere lets designers assign the Blueprint-derived widget asset in the editor.
Frequently asked questions
How do you create a UMG widget in UE5 C++?+
Call CreateWidget<UUserWidget>(GetWorld(), WidgetClass) after including Blueprint/UserWidget.h. The WidgetClass is a TSubclassOf<UUserWidget> property assigned in the editor.
Why is my CreateWidget returning null in C++?+
The most common cause is an unset widget class. Make sure the TSubclassOf<UUserWidget> property is assigned in the editor and null-check it before calling CreateWidget.
What is the difference between CreateWidget and AddToViewport?+
CreateWidget only constructs the widget instance in memory. AddToViewport actually renders it on screen, so you must call both.