x

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"

Assigned UUserWidget* inside of another widget is always reset after compile

Hi, I try to dynamically create an interface using C++, but having an issue with UUserWidget.

The image attached shows some widgets assigned to the custom parent widget declared in C++ which is then placed within the main HUD widget of my project.

alt text

Here is declaration of the Type Button widget (other widgets declared the same way):

 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Menu")
     UUserWidget * TypeButton;

My issue is that after the project is closed or code being compiled the assigned widget values are reset to None. I understand it happens because of the pointers being used, but how do I fix that?

This is after recompile:

alt text

Product Version: UE 4.18
Tags:
ui-01.png (17.3 kB)
ui-02.png (10.5 kB)
more ▼

asked Jun 15 '19 at 12:01 AM in C++ Programming

avatar image

PavelK.
38 2 4 10

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

2 answers: sort voted first

I think I fixed the issue I had. Here is what I did in the header:

     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Menu")
         TSubclassOf<UUserWidget> TypeButton;
   

cpp:

     HorizontalBox->ClearChildren();
     if (Interface.Num() > 0)
     {
         for (int idx = 0; idx < Interface.Num(); ++idx)
         {
             if (auto button = CreateWidget<UUW_Button>(GetWorld(), Interface[idx].TypeButton))
             {
                 HorizontalBox->AddChildToHorizontalBox(button);
             }
         }
     }
more ▼

answered Jun 15 '19 at 09:06 PM

avatar image

PavelK.
38 2 4 10

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

Check your BeginPlay function and constructor in both the code and the blueprint, it's likely being overwritten in one of those. If thatS not the case try changing EditAnywhere to EditDefaultsOnly

more ▼

answered Jun 15 '19 at 05:49 AM

avatar image

kevincvanhorn
63 3 4 8

avatar image PavelK. Jun 15 '19 at 07:54 PM

Thanks for the reply. I tried to change properties to EditDefaultsOnly, but it didn't work. Regarding the Begin play and constructor, here is my code:

 void UMyBadWidget::NativeConstruct()
 {
     Super::NativeConstruct();
 
     HorizontalBox = Cast<UHorizontalBox>(GetWidgetFromName(*FString("Container")));
 
     HorizontalBox->ClearChildren();
     if (Interface.Num() > 0)
     {
         for (int idx = 0; idx < Interface.Num(); ++idx)
         {
             if (auto button = Cast<UUW_Button>(Interface[idx].TypeButton))
             {
                 HorizontalBox->AddChildToHorizontalBox(button);
             }
         }
     }
 }

I see no obvious reason assignment is reset...

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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