Hello!
I’m trying to change text in my textblocks created in Widget Blueprint form c++ code. I can get reference to my WIdget Class by ConstructorHelpers::FClassFinder, then i can create my widget and add it to a vievport. But how do i acces textblocks created in widget blueprint?
i can’t figuer it out.enter code here
.h
/*Main menu BLueprint reference*/
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets")
TSubclassOf<class UUserWidget> wMainMenu;
/*My Main Menu reference*/
UUserWidget* MainMenu;
.cpp
AMyPlayerController::AMyPlayerController(const FObjectInitializer& ObjectInitializer)
:Super(ObjectInitializer)
{
//get my widget blueprint class
static ConstructorHelpers::FClassFinder<UUserWidget> MainMenuCl(TEXT("/Game/Blueprints/GUI/BP_MainMenuWidget"));
wMainMenu = MainMenuCl.Class;
}
void AMyPlayerController::OnMenuShow()
{
bIsShowingMenu = true;
// Create the widget and store it.
MainMenu = CreateWidget<UUserWidget>(this, wMainMenu);
// Extra check to make sure the pointer holds the widget.
if (MainMenu)
{
FInputModeGameAndUI Mode;
Mode.SetWidgetToFocus(MainMenu->GetCachedWidget());
SetInputMode(Mode);
//ok and here is my problem
// how can i acces my textblocks in MainMenu widget from here??? and then set the text of my text blocks.
UTextBlock* text1 = MainMenu-> ??
// or do i have to do it other way?
//let add it to the view port
MainMenu->AddToViewport();
}
//Show the Cursor.
bShowMouseCursor = true;
}