Download

Crash when trying to create a text label from C++

Hallo,

I’m trying to create text labels (in 3d space) from c++, but without success so far. I created a c++ class named “ULabelWidget” (derived from UUserWidget) and create a Widget Blueprint using this class as base-class.

I then create a property in another (actor) c++ class of the type:


 UPROPERTY(EditAnywhere)
   TSubclassOf<ULabelWidget> LabelWidget;

which will properly show up in the properties in the UnrealEditor and I can select my blueprint class, but when trying to attach the widget in C++ (in the ::PostEditChangeProperty handler) using


 WidgetComponent->SetWidget(LabelWidget)

it will crash because


 LabelWidget->WidgetTree == NULL

What’s the problem here ? Why is the WidgetTree always NULL ? What’s the proper way to create 3d labels on my c++ actor ?

Thanks in advance.

Cheers.