UMG Alignment Problem

I’m not certain this is a bug or not. Maybe the problem I’m seeing is due to something I’m doing. Additionally, I have another post that I’m pasting here but with added observations. From my other post:

When my Menu first starts my widgets are aligned as expected. However, when I leave and return to the Menu the text are concatenated. If I reload the Menu level, returning from a game for example, it works fine for the first time. Going into and exiting from sub-menus appear to be giving me a problem.

On my Menu I have a title bar, and a scrollbox that I need to recreate when entering the Menu. The widgets consist of UScrollbox, UHorizontalBox, UCanvasPanel, UTextBlock, UImage, etc.

On a different screen, where the controls are added to the scrollbox using a top level panel (UCanvasPanel), that is, one panel per row, it works as expected. In fact, my Menu originally employed the same technique and worked perfectly except some text was being truncated.

Since working with UE4 and the widgets, I have moved to starting with horizontal boxes (UHorizontalBox) as the top widget for the scrollbox row, then nesting additional horizontal boxes for better control and positioning. And it appears to work well, with the exception of the problem that I’m having.

During construction I use myWidget->ClearChildren(), then build up the control. I’ve tried adding the myWidget->ForceLayoutPrepass() too but that didn’t help. Not sure that it’s a deleting widget issue.

I’ve tried many different gyrations to correct the problem but no luck thus far. Has anyone else encountered a similar problem?

ADDED OBSERVATIONS

I noticed that the Canvas Panel Slots are empty and the MyWidget is invalid the first time through. When trying to reconstruct the widgets a second time the alignment is ignored.

    UHorizontalBox* line = NewObject<UHorizontalBox>(this, UHorizontalBox::StaticClass());
    titleBar->AddChildToCanvas(line);
    FVector2D size = Cast<UCanvasPanelSlot>(titleBar->Slot)->GetSize();
    Cast<UCanvasPanelSlot>(line->Slot)->SetSize(size);
    Cast<UCanvasPanelSlot>(line->Slot)->SetZOrder(0);

    // left spacer box
    UHorizontalBox* leftSpacerBox = CreateHorizontalBox(line, ESlateSizeRule::Fill, 0.1f);
    for (int32 x = 0; x < titleLine.Num(); x++)
    {
        UHorizontalBox* box = CreateHorizontalBox(line, ESlateSizeRule::Fill, titleLine[x].slotSize, titleLine[x].hAlign);
        UTextBlock* text = CreateTextBlock(box, titleLine[x].text, titleLine[x].justify, FLinearColor(1.0f, 1.0f, 0.0f, 1.0f), 28);
    }
    // right spacer box
    UHorizontalBox* rightSpacerBox = CreateHorizontalBox(line, ESlateSizeRule::Fill, 0.1f);



UHorizontalBox* UMyMenuScreenWidget::CreateHorizontalBox(UHorizontalBox* line,
                                                           ESlateSizeRule::Type rule,
                                                           float value,
                                                           EHorizontalAlignment hAlign,
                                                           EVerticalAlignment vAlign)
{
    UHorizontalBox* box = NewObject<UHorizontalBox>(this, UHorizontalBox::StaticClass());
    line->AddChild(box);

    UHorizontalBoxSlot* slot = Cast<UHorizontalBoxSlot>(box->Slot);
    slot->Size.SizeRule = rule;
    slot->Size.Value = value;
    slot->HorizontalAlignment = hAlign;
    slot->VerticalAlignment = vAlign;

    return box;
}


UTextBlock* UMyMenuWidget::CreateTextBlock(UHorizontalBox* line,
                                                   FText text,
                                                   ETextJustify::Type justify,
                                                   FLinearColor color,
                                                   int32 fontSize,
                                                   FMargin margin,
                                                   ESlateVisibility visibility)
{
    UTextBlock* textBlock = NewObject<UTextBlock>(this, UTextBlock::StaticClass());
    line->AddChild(textBlock);

    textBlock->SetVisibility(visibility);
    textBlock->SetText(text);
    textBlock->Font.Size = fontSize;
    textBlock->SetColorAndOpacity(FSlateColor(color));
    textBlock->Margin = margin;
    textBlock->SetJustification(justify);

    return textBlock;
}

Hello ,

I have a few questions for you that will help narrow down what issue it is that you are experiencing.

Quick questions:

  1. Can you reproduce this issue in a clean project?
  2. If so, could you provide a detailed set of steps to reproduce this issue on our end?
  3. Could you provide screen shots of the issue that you are referring to?
  4. Could you provide screen shots of any blueprints that may be involved with this issue?
  5. Could you provide and code necessary to reproduce this issue on our end?

Hello Rudy. . .and thank you for taking the time to respond.

I’m performing additional testing at the moment. Basically, trying to reconstruct my original menu where the controls did align properly. Then I’ll try to render them together.

  1. After my testing, I’ll try to create a new project and see if the problem still exists. This may take me a little while but I’ll let you know, and make it available to you, when I’m done.

  2. I prefer to provide screenshots under separate cover via a PM.

Hello ,

I wanted to check in and see if you were able to reproduce this issue in a clean project and if so, could you provide that project so that I may take a closer look at it?

Hello ,

We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.

Thank you.

Hello Rudy.

I don’t know if it’s a fixed issue, a work around I stumbled upon, or a misunderstanding of the API on my part.

If I move the AddChild() to the bottom of the grouping it works fine but adding after creation causes the alignment problem.

Thank you for the additional information, I am happy to hear that you have resolved your issue. I am going to mark your last comment as the answer for this thread. If this problem returns please feel free to reopen this thread with any additional information.

Make it a great day