# UMG: Visual artifacts when using auto wrap text

**URL:** <https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331>\
**Category:** UI\
**Tags:** text, unreal-engine, question, UMG\
**Created:** [April 8, 2015, 6:16pm UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331 "2015-04-08T18:16:38Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Deventico\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deventico\_1](https://forums.unrealengine.com/u/Deventico_1)\
**Post date:** [April 8, 2015, 6:16pm UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/1 "2015-04-08T18:16:38Z")

</div>

Simple situation: I have a text that get’s wrapped. However when I open the widget, the wrapping only happens after the text has been displayed for some time. It happens quite fast, so it’s not a gameplay issue, but certainly visually annyoing.

Those images should illustrate the issue:

**When opening the widget:**

![38009-before.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/0/e/e0e26f02f13416283564ceba2bd75b357d388380.png)

**After a short amount of time:**

![38010-after_2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/2/a/72a23e7d758a9a4b1cc0e06d81cd6359696ff1ce.png)

The widget opens and closes constantly (depending what button the mouse is hovering over), so the issue is soon noticed by the player.

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [April 8, 2015, 6:33pm UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/2 "2015-04-08T18:33:38Z")

</div>

This is an unfortunate, but known, limitation of the auto-wrapping in Slate.

We can’t auto-wrap the text until we know how much space we have available, and we don’t know that until we’ve done a layout pass. This effectively means that the auto-wrapped text lags behind the desired widget size and can appear to snap when first created.

Are you able to use a fixed wrapping width instead? That doesn’t suffer from this issue as we know what width to wrap at when performing the first layout pass.

---

<div class="post-metadata">

**Author:** ![Deventico\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deventico\_1](https://forums.unrealengine.com/u/Deventico_1)\
**Post date:** [April 8, 2015, 6:36pm UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/3 "2015-04-08T18:36:52Z")

</div>

Thanks for the quick and detailed response!

I think I’ll be able to work with that.

---

<div class="post-metadata">

**Author:** ![Deventico\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deventico\_1](https://forums.unrealengine.com/u/Deventico_1)\
**Post date:** [April 8, 2015, 8:06pm UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/4 "2015-04-08T20:06:35Z")

</div>

One more question tough:

I noticed the same behavior with hidden widgets. I have a widget which contains text. I hide the widget and at some point later in the game I change the text within the widget and display it again. The old text is displayed for a short time and then it changes to the new text.

Do you have any ideas on how to avoid this behavior?

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [April 9, 2015, 10:43am UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/5 "2015-04-09T10:43:09Z")

</div>

Hmm, that’s odd. Text should update at the start of the layout pass.

How are you changing the text?

---

<div class="post-metadata">

**Author:** ![Deventico\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deventico\_1](https://forums.unrealengine.com/u/Deventico_1)\
**Post date:** [April 9, 2015, 11:02am UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/6 "2015-04-09T11:02:15Z")

</div>

First, I set the necessary text:

 ![38144-handle_info_text.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/e/c/9ec2b1163a0df234ab5636f89785755a2505d342.png)

Then I set the visibility of the box:

 ![38145-handle_box.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/f/0/2f0667090eddb77dbac12a74d467f89d0f2ad372.png)

There is a little unrelated code in between, but those are the relevant bits.

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [April 9, 2015, 11:14am UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/7 "2015-04-09T11:14:21Z")

</div>

Is that done in Tick, or in response to some kind of event?

---

<div class="post-metadata">

**Author:** ![Deventico\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deventico\_1](https://forums.unrealengine.com/u/Deventico_1)\
**Post date:** [April 9, 2015, 11:28am UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/8 "2015-04-09T11:28:00Z")

</div>

This is done in Tick. The situation is like this:

I have multiple buttons in one widget and each tick I check wether the mouse hovers over one of them. If it does, I update the text of the info box, depending on the button the mouse hovers over, and set the box to visible.

The issue occurs when the mouse hovers over button A, then hovers over nothing and after that hovers over button B. The text of A gets displayed and quickly but not instantly changes to the text of B.

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [April 13, 2015, 4:31pm UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/9 "2015-04-13T16:31:16Z")

</div>

Sorry for the delay in getting back to you on this.

The reason this happens is because `Tick` is called after Slate has already done its pre-pass step. It is this step that updates the desired size of a widget before performing the rest of the layout and paint passes.

Since you’ve set the text after the widget has had its size cached, and since `STextBlock` only updates its text in `ComputeDesiredSize`, the visible text cached in the widget won’t be updated until the next pre-pass step (and even if it were updated immediately, the size would be wrong and you’d potentially get clipped text).

If there’s no better place for this logic than `Tick`, I’d suggest updating the text and then setting the widget to `Hidden` (as an aside `Hidden`, unlike `Collapsed`, will still have a pre-pass done on it). You can then set the visibility to `Visible` on the next `Tick` as the text will be up-to-date, although this may introduce a perceived lag in your UI.

Alternatively you could experiment with using bound functions for your text and visibility (although I’d suspect these would have the same issues as they’re not cached so the text would still change between pre-pass and paint), or you could use the “Force Layout Prepass” node to force your text to update (and the widget to re-size) after setting the new text.

---

<div class="post-metadata">

**Author:** ![Deventico\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Deventico\_1](https://forums.unrealengine.com/u/Deventico_1)\
**Post date:** [April 13, 2015, 5:29pm UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/10 "2015-04-13T17:29:09Z")

</div>

Thank you very much, this is a very detailed and absolutely helpful response!

If I’m not mistaken I tried to use bound functions and they didn’t fix it either.

But I’ll definitely try the “Hidden for one more tick”-trick and if that lags, I’ll use “Force Layout Prepass”.

---

<div class="post-metadata">

**Author:** ![ellocator](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ellocator](https://forums.unrealengine.com/u/ellocator)\
**Post date:** [January 9, 2018, 1:02pm UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/11 "2018-01-09T13:02:43Z")

</div>

Sometimes it is also permanently reporting the wrong size, not just delayed by one tick. Even with fixed size wrapping.

Is there a way to force the recalculating of the size? I already tried in the tick:

```
InvalidateLayoutAndVolatility - no effect
SynchronizeProperties - no effect
Setting text to empty, then the text again - no effect
ForceLayoutPrepass - makes it worse, it will not even correct itself after 1 tick with that
SetVerticalAlignment - no effect
RebuildWidget - no effect
ComputeDesiredSize - no effect

```

There must be some code that is called 1 tick later which fixes it, but sometimes that code is not called and I need to call it manually. But what code is it? Maybe TextLayoutCache is permanently wrong? But I don’t see where it is ever refreshed and it is also not accessible from outside.

---

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [January 9, 2018, 2:15pm UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/12 "2018-01-09T14:15:10Z")

</div>

@ellocator Try [ForceLayoutPrepass](https://docs.unrealengine.com/latest/INT/BlueprintAPI/Widget/ForceLayoutPrepass/).

---

<div class="post-metadata">

**Author:** ![ellocator](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ellocator](https://forums.unrealengine.com/u/ellocator)\
**Post date:** [January 10, 2018, 9:04am UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/13 "2018-01-10T09:04:16Z")

</div>

I further tracked the issue into the depth of the engine and it turns out the text field actually can calculate its correct size with ComputeDesiredSize. It’s just never used. Instead the SScaleBox parent sends the wrong AllottedGeometry with TheChild.Geometry to the STextBlock. So I will now investigate how to fix the scalebox to calculate the correct geometry.

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [January 10, 2018, 12:04pm UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/14 "2018-01-10T12:04:31Z")

</div>

Which version are you on?

---

<div class="post-metadata">

**Author:** ![ellocator](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ellocator](https://forums.unrealengine.com/u/ellocator)\
**Post date:** [January 10, 2018, 1:19pm UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/15 "2018-01-10T13:19:21Z")

</div>

4.18.2

I also now found a fix. The issue was in SScaleBox::OnArrangeChildren

As already known, the first desired size is wrong, that’s why another one is calculated in `if(bRequiresAnotherPrepass)`. The issue was that the LastFinalOffset is calculated before that in `if ( CurrentStretch != EStretch::Fill )`.

So what I did was, swap the two blocks. Which means the LastFinalOffset is now calculated with the corrected desired Size in mind.

(The scalebox we use is EStretch::ScaleToFit and has bSingleLayoutPass=false, so it is doing that double size calculation every frame, but it seems to be tolerable performance-wise.

Also LastSlotWidgetDesiredSize remains the wrong size at the end of the function, but that does not seem to cause any problems.)

---

<div class="post-metadata">

**Author:** ![StapledBattery](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@StapledBattery](https://forums.unrealengine.com/u/StapledBattery)\
**Post date:** [February 19, 2026, 7:47pm UTC](https://forums.unrealengine.com/t/umg-visual-artifacts-when-using-auto-wrap-text/314331/16 "2026-02-19T19:47:12Z")

</div>

I’ve had similar issues that weren’t resolved with ForceLayoutPrepass. Tricks like setting opacity to zero for a couple frames while things resolve themselves work, but that’s a visual artifact in and of itself. With a little bit of c++ I was able to do a full paint when adding the widget, which does solve the problem.

Header file:

```auto
UCLASS()
class UYourBlueprintLibrary: public UBlueprintFunctionLibrary {
	GENERATED_BODY()
	// Repaint the widget. Use when ForceLayoutPrepass isn't enough. Only works if the widget is already displayed. Will call Tick for all widgets in the hierarchy, so be careful to avoid infinite recursion. Best if used on the immediate parent of a newly added widget, and never on `self`.
	UFUNCTION(BlueprintCallable)
	static void ForceWidgetRepaint(UWidget* Widget);
};

```

c++ file:

```auto
void UYourBlueprintLibrary::ForceWidgetRepaint(UWidget *Widget) {
	TSharedPtr<SWidget> slateWidget = Widget->GetCachedWidget();
	if (!slateWidget) {
		UE_LOG(LogTemp, Warning, TEXT("Cannot repaint widget %s that has no underlying slate widget"), GET_NAME_STR(Widget));
		return;
	}
	TSharedPtr<SWidget> windowWidget = slateWidget;
	TSharedPtr<SWindow> windowWindow = nullptr;
	do {
		windowWidget = windowWidget->GetParentWidget();
		if (NL(windowWidget, Advanced_IsWindow())) windowWindow = StaticCastSharedPtr<SWindow>(windowWidget);
	} while (windowWidget && !windowWindow);
	if (!windowWindow) {
		UE_LOG(LogTemp, Warning, TEXT("Cannot repaint widget %s that is not in a window."), GET_NAME_STR(Widget));
		return;
	}

	FSlateWindowElementList windowElementsDiscard(windowWindow);
	FPaintArgs paintArgs(slateWidget->GetParentWidget().Get(), windowWindow->GetHittestGrid(), FVector2D::Zero(), FApp::GetCurrentTime(), 0);
	FGeometry geometry = slateWidget->GetTickSpaceGeometry();
	slateWidget->Paint(paintArgs, geometry, geometry.GetLayoutBoundingRect(), windowElementsDiscard, 0, FWidgetStyle(), windowWindow->IsEnabled());
}

```

As pointed out in the comment, this only works if you give it a widget that has already been painted in a previous frame. The main use-case is if you add wrapped text to a panel, e.g. a vertical box, you can then call the ForceWidgetRepaint node on that panel to avoid glitching.
