How to create a UMG widget instance using c++

Hello, I am trying to create an instance of a UMG widget using c++. The widget was created using the UMG editor.

I am working in the character files, in the character.h I have:

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
	TSubclassOf<UUserWidget> WidgetTemplate;

UUserWidget* WidgetInstance;

The WidgetTemplate is being set in the blueprint derived from the character class.

Then in the BeginPlay function in the character.cpp I am trying to use the CreateWidget function to set the value of WidgetInstance like so:

if (WidgetTemplate)
{
        WidgetInstance = CreateWidget<UUserWidget>(this, WidgetTemplate);

		if (WidgetInstance nstance) {
			//let add it to the view port
			WidgetInstance ->AddToViewport();
		}
}

The problem arises with the CreateWidget function.

Any help would be appreciated.
Thanks,
.

After spinning my head over this stupid error for a while I had the 1st argument wrong - for anyone interested use CreateWidget(GetWorld(), WidgetTemplate);

Thank you so much, I was stocked by this stupid question too…

i think this video will be helpfull. How to Spawn/Create Widget in Unreal Engine C++ - YouTube