How to create a variable of a custom type is C++

I have a basic First Person character, and i want to declare a variable of type widget component.
Though my question is, besides including the #include “Components/WidgetComponent.h”
in the header file.
how do i assign a BP widget i created in unreal, to the variable i want to create ?

Overall, i need to get access to that WBP, to set the name displayed in the Widget.

Hope you understand what i mean. will upload photos if needed.

Go to YourGameName.Build.cs, and you will see line that contains array of strings. It looks something like this: PublicDependencyModuleNames.AddRange("Core"....) you need to add "UMG" in that array.

Then in your character

UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "UMG")
TSubclassOf<UUserWidget> CustomWidget;

Then open your editor and Character class where you added the code above. You will see something like this, and you will be able to add any widget you want.

Amazing, thank you for the replay ! just what i needed.

i cant seem to get a variable from that widget any help ?

Derive a C++ class from UUserWidget, declare the variable there, parent your blueprint widget to that.

Then in that first person character just have TSubClassOf CustomWidget.

Your C++ classes cannot read variables declared in blueprint classes.

If you want to get variable in C++, then you have to create that widget in C++, and use it in the blueprints.

i ended up doing something else, because it created a class (purple)
and i need the actor ref - blue object reference.