Unable to Put Multiple New Lines in Godot 4 RichTextLabel

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By jaberwok2010

Is there a way to insert multiple new lines into a RichTextLabel?

I have tried the method I used in Godot 3.X – “\n\n\n” – but Godot 4 appears to ignore anything beyond the first “\n”. (This is true in the editor as well; regardless of how many times I hit enter, the text displayed does not move.)

In response to inquiry on the Godot subreddit, I got several suggestions which did not pan out – including using [br] or
(which do not work at all) and using RichTextLabeling.newline() (which appears to behave identically to \n).

Godot 3.x allowed multiple newlines in a row in RichTextLabels. Although this change feels like it was intentional, I do not understand the reasoning for it, nor can I find any commentary explaining it.

Can someone please explain to me what I’m missing?

:bust_in_silhouette: Reply From: jgodfrey

\n works fine for me: So…

$RichTextLabel.add_text("A new string")
$RichTextLabel.add_text("\nA second new string")

Oh, just noticed that you mentioned that you can’t get it to work in the editor either. In my case, I can type as many lines as I want in the inspector simply by pressing Enter between them. I am using 4.0.2, but I’d expect it to work the same in 4.0.3…

jgodfrey | 2023-06-06 20:45

Do you see the same problem with a freshly created RichTextLabel? (just wondering if you’ve inadvertently changed a control property that’s interfering with your results.)

jgodfrey | 2023-06-06 20:48

Progress! Thank you very much for the suggestion. A newly created RichTextLabel in the same project did not suffer this issue… until I tried to replace the poorly-behaved RichTextLabel with the new one.

After some digging, it appears that this behavior occurs when I load a FontFile in Theme Overrides. This occurs regardless of whether there’s an actual font resource loaded into that FontFile or not. This does not seem like intended behavior, but it’s at least narrowed down the reasons for the issue.

jaberwok2010 | 2023-06-06 21:50

Yeah, I can recreate your issue here based on your last comment. Agreed, it doesn’t feel like intended behavior. I took a quick look at the issues associated with the 4.x RichTextLabel control but didn’t notice anything that seems related. You might consider filing a bug report.

jgodfrey | 2023-06-06 22:11

Thank you very much for your help!

Edit: Bug report filed!

jaberwok2010 | 2023-06-06 22:50