Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

TextMesh Pro TMPro won't display strings on new line in Unity2020LTS

Discussion in 'UGUI & TextMesh Pro' started by Idialot, Apr 22, 2023.

  1. Idialot


    Dec 8, 2013
    I am not sure what I am missing here.

    I wish to display several lines of text gathered from a list.

    This is the code that worked in 2019 and not sure what is happening here. I have read through all the posts using many methods such as appending \n, <br> \u000a. string.replace() ETC.

    if I do the following it works.
    string name = "Name1\nName2\nName3"
    nameText.text = name;

    and the output to the UI text field is

    Name3 as it should be.

    But this line of code does not work when it did before in 2019, so if anyone has any suggestions I would appreciate it as this is driving me nuts. (Relative Newbie).

    I am looping through an array of stats grabbing the name of the stat and the value of the stat and wish them to display in a single text field in the UI in two separate text fields. One for names and one for values.

    for (int i = 0; i < selectedItem.item.consumables.Length; i++) {

    selectedItemStatsName.text = selectedItem.item.consumables.type.ToString() + "\n";

    if (selectedItem.item.consumables.value < 0) {

    selectedItemStatsValue.text = string.Format("<color=yellow>{0}</color>",
    selectedItem.item.consumables.value.ToString() + "\n");
    else {

    selectedItemStatsValue.text = string.Format("<color=green>{0}</color>",
    selectedItem.item.consumables.value.ToString() + "\n");

    All that displays is the last string on the top line. This has me boggled for sure. Not sure if this is a bug in Unity or TMPro or if there is a new way of doing it in the 2020 version. Just a note that in the code above, type is an enum for stat type.