I’ve done some experiments with HUD and UserWidgets
. I have created the UMyHUDWidget
class and extended the UUserWidget
class.
1) MyHUDWidget
contains some additional variables which are exposed to the Blueprints, for example a reference to a UTextBlock
(variable contextActionText
)
UCLASS()
class PROJ_API UMyHUDWidget : public UUserWidget
{
GENERATED_BODY()
public:
UMyHUDWidget(const FObjectInitializer& ObjectInitializer);
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = ContextActionTrigger)
UTextBlock* contextActionText;
};
Then, in blueprints, I try to set the contextActionText
variable with a existing UTextBlock
reference. The blueprint debug shows that the variable is properly set.
But back in the code, the contextActionText == nullptr
.
Then, I try to do something similar:
2) I create the same variable in a player actor class.
UCLASS(config = Game)
class AMyCharacter : public ACharacter
{
GENERATED_BODY()
public:
AMyCharacter(const FObjectInitializer& ObjectInitializer);
// some other properties and methods ommited
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, Category = ContextActionTrigger)
UTextBlock* contextActionText;
};
Then again, I set the variable in blueprint and voila! The variable contextActionText
is passed to C++ and is properly set.
EDIT1: The assignment is done in the blueprint derived from UMyHUDWidget
class.
Did something change in the second scenario? How come that the first scenario doesn’t work and the second one does? Is the variable treated differently when extending from ACharacted
rather than UUserWidget
?
Any suggestions are welcome