How to line break within Rich Text Block?

Hi there,

I’m using the Rich Text Block to display dialogue in my project, and it currently reads from a data table with text strings. Some of the strings are supposed to be formatted like paragraphs, but I’m not sure how to get a carriage return to display in the text.

I’ve tried to use "
" within the text string, but it just shows up as "
" instead of creating a line break. I also saw that “Shift+Enter” should work to push text onto a new line, but this didn’t work for me either. Any help with this would be greatly appreciated! :slight_smile:

1 Like

Perhaps not a timely reply, but hope this is still useful to someone at least. I know this specific question had me banging my head back in early UE4 days…

Irritating, but string variables do not know what to do with a traditional line break inserted in-line in the middle of a string, and don’t see a /n by itself as anything special.
You have to use the Format Text block. Format text is great because you can replace a specified sub-string or strings within a larger string with something else.
In this case, we want to replace a /n with a line break.

Here’s a quick blueprint example.
You’ll need to add a “what to search for & replace” entry on the Format Text block, and specify it as /n.
Then, you need to pipe into it what you want to replace the /n with. In this case, “Shift + Enter” will add a line break. Use the Make Literal text.
Then pipe the formatted text output into the SetText of the RichText entry of your widget!

Your string needs to have whatever you want replaced with { }. The { } are deliminator that tells a Format Text block that something in between these is something we’ll want to replace.
In this case, the /n in your string need to be **{/n}.

FormatTextLineBreak2.PNG**

String in data tables will work just fine this way too. Just add a {/n} every place in your strings you want a line break, make sure that the SetText is using a Format Text, and done!

This doesn’t really tell you much about how to specifically use it but here’s the Unreal page:

10 Likes

Hello,
Super Helpful ! Thank you !

Thank you!

Thanks a lot for the suggestion. this is still an issue in 5.2. i wish you could enter multilines directly on datatables using shift+enter.
Also it seems i can’t use the format trick with a text from a datatable since the format node can’t see the {} variable.

You can, simply add the UPROPERTY meta “Multiline=true” UPROPERTY(meta=(MultiLine=true)) to your C++ FText variable declaration for the Data Table Row.

See: All UPROPERTY Specifiers · ben🌱ui

As for the format trick, you just need to set it up like the screenshot EricWack posted where you plug your data table’s FText variable into the “Format” pin, and then click on the Format Text node and hit “Add Pin” to add whatever { } modification you want. For example a pin called {/n}.

2 Likes