Add a new line inside a Text var

Hello guys!

I ran into a problem with setting text inside UMG.

As you may know, you can add ne line by pressing Shift + Enter inside text block. Like this:

But the problem is that I have custom event, that sets my text from a variable and I have no Idea how to add new line, because Shift + Enter does no effect on my text.

Soo… How do I add a new line in text variable in order to set Widget Text??

3 Likes

It’s usually \n in C++ but I’m not sure if it would work here.

1 Like

In 4.8, Shift+Enter adds line breaks to nodes.

9 Likes

This is a workaround for now I’ve got this guy in a separate BPMacro library (encase of catistrofic death down the road but it works for now.

But I don’t need it for String. I need it for Text variable…

snap missed that it was late :stuck_out_tongue: idk if that will apply to a text variable but it is convertible just drag a pin on and on to a text pin it will convert. I’ve got them on multiline text boxes witch run off of text rather than strings.

This no longer works in 4.8, by the way.

Lol… They ruined last hope in making multi-line text :smiley:

Like I said earlier, you can just do Shift + Enter for line break :slight_smile:

Like I said in the first post, I need to make newline in a variable… And 4.8 is not the answer.

Because text in widget sets from variable, which I set on exact instance of the object with Construction Script. So I want to select my note in viewport and type the text I need in Details panel. But I cannot make newline there…

It is indeed impossible to add line breaks to a variable. However, there are multiple ways of doing that via scripting. In simple cases (which, I agree, is not your case), the following is possible:

In your case, you can use the Format Text node, like this. Drag a line out of a variable of type Text, and type “Format Text.” This node will let you insert line breaks wherever you want like in the example below.

To rename the pin, select the Format Text node and go to Details.

43107-screen+shot+2015-05-18+at+0.59.47.png

I hope this helps.

10 Likes

Hmm, The way with format text should work fine. Thank you!

O.o thats some good magic thank you for that, will be changing my code now. Make sure this is marked answered if it works for yea. :slight_smile:

Make a multiline textbox in UMG, use shift+enter to add a single new line.

On HUD construction, get the text from the multiline text box and save it to a variable (string or text).

Now you can use that to append newlines.

Ingenious trick. Thanks for this!

Hey
When you are in Editor you can just use
to make a newline.

Hey you can just use
to seperate lines.
At least in the Standard Editor

Lol sry I didnt see that html code works in this text block xD

You have to use < br > without space ^^

You can add a meta "MultiLine " to do that:

UPROPERTY(EditInstanceOnly, meta = (MultiLine = true))
FText ItemDescription;
4 Likes

This is exactly what I was looking for. Thanks!
How do you find these undocumented UPROPERTY specifiers (especially those mysterious meta ones)? Where can I look in the source?