I need to store a pointer to my HUD widget in a C++ character class. I have tried several solutions, most involving code like this: ConstructorHelpers::FClassFinder<UUserWidget> BPClass(TEXT("Game/..."));
. Unfortunately, everything I try throws several errors and I do not know what I am supposed to do with the result of this code. Any advice?
BPClass that you declare is still of FClassFinder type, not of your widget type.
BPClass.Object is your UUserWidget.
Try something like UMyWidgetClass = Cast<UMyWidgetClass>(BPClass.Object);
And then use UMyWidgetClass when you create the widget.
Alternatively, if you’re creating a blueprint based on this c++ class, you can simply declare something like
UPROPERTY(EditAnywhere)
TSubclassOf<UMyWidget> UMyWidgetClass;
and set the class in your BP details.
2 Likes