Download

Manipulate BP widget items from C++

Hello

I have the following problem
I would like to change text in text box in my BP widget using C++ code. I have created BP class derived from my C++ class.

That is the part of my code in *.h file in my class:


UFUNCTION(BlueprintCallable, Category = "ATest")
void OnTestPressed();

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "BP Classes")
TSubclassOf<UTextBlock>	testTextBlockBPClass;

The part of my code in *.cpp file in my class:


void UMyWidget::OnTestPressed()
{
	if (testTextBlockBPClass)
	{
		UTextBlock* txtBlock = (UTextBlock*)testTextBlockBPClass->GetClass();
		txtBlock->SetText(FText::FromString("Can you see your text?"));
	}
}

Clicking by button I am trying to change text in my text box that is at widget.
This is how I am using blueprint script to setup my variables:

Why I did not see the text after clicking by button?
Someone please help me.

I know this is not answering the question, but if you don’t get an answer, I find this works…

9e14259c5de31d604d2b3f693d3695eb83e9a301.jpeg


UCLASS()
class STRANGEORBITZ_API UStrangeOrbitzUserWidget : public UUserWidget
{
	GENERATED_BODY()

	
public:
	UStrangeOrbitzUserWidget(const FObjectInitializer& ObjectInitializer);

	UPROPERTY(Category = StrangeOrbitz, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
	FText TopText;

	UPROPERTY(Category = StrangeOrbitz, VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
	FText BottomText;

};