Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to use a widget function inside myCharacter class


I have a problem to put widget in my Character Class.

my GameMode class has a UUseWidget already like below.



 UFUNCTION(BlueprintCallable, Category = "UMG")
 void ChangeMenuWidget(TSubclassOf<UUserWidget> NewWidgetClass);
 UUserWidget* GetCurrentWidget() const;


 virtual void BeginPlay() override;
 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "UMG")
 TSubclassOf<UUserWidget> StartingWidgetClass;
 UUserWidget* CurrentWidget;



void ADDModeBase::BeginPlay()




void ADDModeBase::ChangeMenuWidget(TSubclassOf NewWidgetClass)


 if (CurrentWidget != nullptr)
     CurrentWidget = nullptr;
 if (NewWidgetClass != nullptr)
     CurrentWidget = CreateWidget<UUserWidget>(GetWorld(), NewWidgetClass);
     if (CurrentWidget != nullptr)


UUserWidget* ADDModeBase::GetCurrentWidget() const


 return Cast<UUserWidget>(StartingWidgetClass);


Here I want to use StartingWidgetClass that is a UUMG_PlayUI class in myCharacter Class.

I had to create UUserWidget* Name; variable. but i can get that StartingWidgetClass.

Actualy, UUMG_PlayUI! without CreateWidget<>.

How to use a userwidget's function in my character class?

Product Version: UE 4.18
more ▼

asked Dec 14 '17 at 01:51 AM in C++ Programming

avatar image

1 1

avatar image birdfreeyahoo Dec 14 '17 at 02:27 AM

Do I understand you right, that you want to call a function which you declared in your widget blueprint? I don't think that is directly possible. The way, you can call blueprint functions is by declaring a BlueprintNativeEvent in your C++ class and have a blueprint implementing it. Then you can call it in your code and the logic inside the blueprint gets executed.

avatar image LoveLim Dec 14 '17 at 02:38 AM

I have created some function in UUMG_PlayUI with C++. not blueprint.

void ACharacterPC::BeginPlay() { Super::BeginPlay(); ADeepForestGameModeBase* GameMode = (ADeepForestGameModeBase*)GetWorld()->GetAuthGameMode(); UMG = CreateWidget(GetWorld(), GameMode->StartingWidgetClass); }

This is the code to referencing the widget. The UMG can't get the correct widget. This is the problem. Some way, I can get the UUMG_PlayUI. but created variables are null.

avatar image birdfreeyahoo Dec 14 '17 at 02:49 AM

So the problem is that UMG variable in Character is null? What is the type of this variable and is StartingWidgetClass set?

There is a problem in your code: Your GetCurrentWidget function will likely return a nullpointer

avatar image LoveLim Dec 14 '17 at 03:08 AM

Right. the GetCurrentWidget is not using currently. I might don't know how to get UserWidget from the world().

UUMG_PlayUI::UUMG_PlayUI(const FObjectInitializer& PCIP) :Super(PCIP)

{ textDisplay = nullptr; textComboBox = nullptr; }

void UUMG_PlayUI::NativeConstruct()

{ Super::NativeConstruct();

 if (textDisplay == nullptr)
     textDisplay = (UTextBlock*)GetWidgetFromName(TEXT("DisplayText"));
     textDisplay->SetText(FText::FromName(TEXT(" ")));
 if (textComboBox == nullptr)
     textComboBox = (UTextBlock*)GetWidgetFromName(TEXT("ComboBox"));
     textComboBox->SetText(FText::FromName(TEXT(" ")));


void UUMG_PlayUI::SetCombo(int32 ComboCount)

{ FString Info = FString::Printf(TEXT("COMBO : %d"), ComboCount); textComboBox->SetText(FText::FromString(Info)); } void UUMG_PlayUI::SetDisplay(FString Info) { textDisplay->SetText(FText::FromString(Info)); }

This is my UMG_PlayUI class. In Character class, want to call the SetCombo function like SetCombo(ComboCount);

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question