Answer the question
In order to leave comments, you need to log in
How to get a reference to a UI element in c++?
Hello. I created a UI using the Blueprint class(Widget) and now I want to get a c++ reference to its elements (buttons, pictures, etc.). How can I do this?
Answer the question
In order to leave comments, you need to log in
Don't use NewObject to get a reference to the UUserWidget class. With this approach, BindWidget simply won't work and your widget references will be null.
For example, you can do this. I create a "Say Hello world" button in the blueprint widget.
Further, for example, in the C ++ class GameMode I will add a new function that will display a message on the screen.
GameMode.h
UFUNCTION(BlueprintCallable, Category = "Custom")
void SayHello();
void AMyGameModeBase::SayHello()
{
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Orange, TEXT("Hello World"));
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question