Multiline textarea with style not working :(

Help me with this and I will love you forever.

When I make a multiline textarea like this…

var stringToEdit : String = "Hello World\nI've got 2 lines...";

function OnGUI () 
{
stringToEdit = GUI.TextArea (Rect (10, 10, 200, 100), stringToEdit, 200);
}

…it works perfectly. (Well, of course it does, since it is straight copy and paste from the documentation).

  • But when I add a style like this…
var stringToEdit : String = "Hello World\nI've got 2 lines...";

var someStyle : GUIStyle;

function OnGUI () 
{
stringToEdit = GUI.TextArea (Rect (10, 10, 200, 100), stringToEdit, 200, someStyle);
}

…you can no longer use Enter/Return to make a new line break. I tried changing each style property at a time, but none seems to make it work. Can someone please help me?

My friend. Unfortunatelly no Unity developer does know what is going on inside of TextArea, DoTextField or other similar APIs… I spent a lot of time to get answer to a similar question without any positive result

This was recently reported as a bug (case 381509) but it isn’t fixed yet. You can actually type newlines in the textarea but you need to use alt+return, which is clearly incorrect behaviour.