Inconsistent text size with Wrap Text At + Scale Box

Hello all,

THE INFO

I have a widget with a Text Box wrapped in a Scale Box.

-The Scale Box is set to Scale to Fit in both directions.

-The Text Box’s alignment is Fill Horizontally and Fill Vertically. The text is centered and set in runtime, its length ranging from 100 to 300 characters aproximately, and it is supposed to fill all the space. If the text is shorter, its size should be increased; while if it’s too long, it should be sized down to fit the box without overflowing it.

If I leave Wrap Text At as 0, the text is displayed as a single, tiny line. Enabling Auto Wrap doesn’t really make a difference. I’ve been trying to find a Wrap Text At value that is appropiate for different lengths, but it never acts as expected: the text looks too small even if there is enough space for it, or it overflows the textbox.

This is how texts of different lengths look right now, with a Wrap Text At value of 1812 (this is simply the number I have found works “less bad”, simply by trying out values, but it still has some issues):

Short text (126 characters): Looks decent, but doesn’t fill the brown box even though there is free space.
ShortText

Medium text (186 characters): Keeps a reasonable size, but could fill the box better. If I reduce the window size, it becomes smaller with the other elements of the widget, but the text overflows.
MediumText
MediumText_overflow

Longer text (206 characters): Becomes unnecessarily small and leaves too much empty space.
LongText

Other Wrap Text At values do make longer texts look good, but of course they don’t work for smaller texts.

And this is te Scale Box size in relation to the brown box:

THE QUESTIONS

-Is there any combo of Scale Box + Wrap Text At (or any other option / setting that I’m missing out) that can make text of any length (within reason) appropiately fit, resize and not overflow its limits? I’ve read several threads and haven’t really found a good answer.

-In case there definitely isn’t an easy fix, I guess the only solution is to calculate and set Wrap Text At in runtime, depending on the text’s number of characters. However, I don’t know what value to use as a reference. What unit is this value in? It’s not number of characters nor text box sixe (in my widget, the scale box that wraps the text box is 633x249px). How do I know what value is appropiate for a certain number of characters (other than just testing different numbers)?

This little issue has been driving me nuts for a while since the text size seems to be very inconsistent, even more so if you test it on different screen sizes (it can look tiny in smaller devices even if there is enough space for it), so any help is appreciated! Thank you!

EDIT: I have just discovered there is no node to set the Wrap Text At value from the widget’s graph, so… Not sure what to do anymore :upside_down_face:

I really don’t recommend calculating text line width and apply manual wrap, as for each character appended, you will need to check the width and do a ForceLayoutPass which will be costly(i spend weeks on that to find out it not worth the perf cost).

I suggest changing method, do you really need the scale box ?, the AutoWrap should be working fine and text box justify to center(with some padding if needed).

From my own experience, i often play on console on tv, lot of game don’t provide Text Font Size setting, but game like ff13 do and it so useful. I think just providing an option to increase dialogue text font might be more useful(depending on your game ofc) as you might spend weeks on that instead of a simpler solution.

Hi, thanks for your answer! I’ve tried removing the Scale Box, but now longer texts always overflow the box unless I reduce the font size, which is not desirable for shorter texts because it leaves too much unused empty space.

overflow
imagen

Besides, I can’t predict how much longer or shorter these texts will be in different languages, that’s why I was counting on a Scale Box to reduce the size if they were too long to fit at the default size.

As for the performance cost of applying manual wrapping that you mention, rather than checking the width for each character appended I was planning on setting the full text and then calculating and setting the Wrap Text At Value. Something similar to what this person was trying to do: UMG: Scale Box and Wrap Text - #2 by SolidSk Do you think that would be as expensive? :thinking:

Thanks again!

I think I have tried every possible combination of Scale Box + Text Box settings by now, to no avail. I have also tried replacing or wrapping the Scale Box with a Size Box, but it doesn’t make much sense it doesn’t size the text down when it’s too long.

I haven’t found a way to set the Wrap Text At value in runtime, either, so it seems there is no way to make dynamic text of (slightly) variable length adapt its size to fit a fixed-size text box…? It’s quite weird since this is a common feature in games, especially if you take localization into consideration. There has to be a way to fit a text into a box regardless of its length / number of characters.

Bumping since I haven’t found a solution and I’m sure there’s something I must be missing or misinterpreting :frowning:

I’d really like an answer to this too.

i solved the problem with setting “Wrap Text At” manually :slight_smile: