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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

[UMG]UUserWidgets are invisible when added via c++

I'm fairly new to UE4, having a pretty strong Unity background. Right now, what I'm trying to do is create a progress bar that displays the rewards at various levels. I'm using a pair of Horizontal Boxes in an Overlay, which is in an Overlay with the progress bar.

Hierarchy as it stands right now

I also have a custom widget that populates the horizontal boxes with the following function:

 void UTurretProgressBarWidget::InitializeProgressBar(APlayerController* OwningPlayer)
 {
     for (int i = 0; i < MaxLevel; i++)
     {
         UImage* Bar = WidgetTree->ConstructWidget<UImage>(UImage::StaticClass());
         if (Bar)
         {
             UPanelSlot* slot = HorizontalPanelBack->AddChild(Bar);
             UHorizontalBoxSlot* BarSlot = Cast<UHorizontalBoxSlot>(slot);
             Bar->SetColorAndOpacity(FLinearColor(0, 0, 0,1));
             Bar->Brush.ImageSize = FVector2D(4, 32);
             BarSlot->SetHorizontalAlignment (EHorizontalAlignment::HAlign_Left);
             BarSlot->SetVerticalAlignment(EVerticalAlignment::VAlign_Fill);
             FSlateChildSize size = FSlateChildSize(ESlateSizeRule::Fill);
             BarSlot->SetSize(size);
             //BarSlot->Size.Value = 1.0f;
             if (LevelStride > 0)
             {
                 if ((i+1) % LevelStride == 0)
                 {
                     //UTurretLevelSymbolWidget* tempLevelWidget = WidgetTree->ConstructWidget<UTurretLevelSymbolWidget>(MaxLevelWidget->StaticClass());
                     UTurretLevelSymbolWidget* tempLevelWidget = CreateWidget<UTurretLevelSymbolWidget>(OwningPlayer);
                     if (tempLevelWidget) 
                     {
                         tempLevelWidget->AddToViewport(1000);
                         tempLevelWidget->SetColorAndOpacity(FLinearColor(1, 1, 1, 1));
                         UPanelSlot* tempSlot = HorizontalPanelFront->AddChild(tempLevelWidget);
                         UHorizontalBoxSlot* levelslot = Cast<UHorizontalBoxSlot>(tempSlot);
                         levelslot->SetHorizontalAlignment(EHorizontalAlignment::HAlign_Fill);
                         levelslot->SetVerticalAlignment(EVerticalAlignment::VAlign_Fill);
                         levelslot->SetSize(size);
                         //UE_LOG(LogTemp, Warning, TEXT("CreatedWidget"));
                     }
                     else
                     {
                         UE_LOG(LogTemp, Warning, TEXT("Unable to create widget!"));
                     }
                 }
                 else
                 {
                     USpacer* spacer = WidgetTree->ConstructWidget<USpacer>(USpacer::StaticClass());
                     if (spacer) {
                         //spacer->SetSize(FVector2D(1.f,1.f));
                         UPanelSlot* slot = HorizontalPanelFront->AddChild(spacer);
                         UHorizontalBoxSlot* SpacerSlot = Cast<UHorizontalBoxSlot>(slot);
                         FSlateChildSize size = FSlateChildSize(ESlateSizeRule::Fill);
                         SpacerSlot->SetSize(size);
                         SpacerSlot->Size.SizeRule = ESlateSizeRule::Fill;
                         //SpacerSlot->Size.Value = 1.0f;
                     }
                     else
                     {
                         UE_LOG(LogTemp, Warning, TEXT("Error Spacer is null!"));
                     }
                 }
             }
         }
     }
 }

For whatever reason, the widget that I create via "CreateWidget" is invisible. What am I doing wrong here?

Edit: D'oh! I saw a typo where I was storing a UImage in a USpacer. The widgets are still invisible, though.

Product Version: UE 4.13
Tags:
more ▼

asked Nov 04 '16 at 01:03 AM in C++ Programming

avatar image

firestorm713
26 2 5

avatar image MajinSephiroth Nov 04 '16 at 01:29 PM

Is your "OwningPlayer" reference passing forward the intended player controller?

avatar image firestorm713 Nov 04 '16 at 05:17 PM

As far as I can tell. I use a simple "Get Player Controller" call in blueprints and pass that reference into the function when it's time to call it.

Notably, I can confirm that the widgets are being created based on the child count of the object they're being parented to.

avatar image MajinSephiroth Nov 05 '16 at 05:24 AM

I'm just curious of whether the widgets are being assigned to the proper player controller (assuming more than one exists) if only one exists, I suggest using the widget reflector in the editor and determining if they are sized correctly and placed appropriately.

avatar image firestorm713 Nov 07 '16 at 08:09 PM

Sounds good. I was actually wondering if there was a way to inspect widgets on the fly. The Widget Reflector sounds like exactly what I was looking for.

(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