TMP using string + string result overlapping in game

i have variable and properties like this,

[Serializable]
public class Character
{
public string firstName = "FirstName";
public string lastName = "LastName";

    public string GetFullName
    {
        get
        {
            //I also has tried this(commented),
            //string fullName = String.Concat(firstName + " ・ " + lastName);
            //string fullName = String.Join(" ・ ", firstName, lastName);

            string fullName = firstName + " ・ " + lastName;
            return fullName;
        }
    }
}

and in the other class i call the properties by,

public void SetFullName(Character chara)
    {
        nameText.text = chara.GetFullName;;
    }

and the result become,


question= why text become centered like that, and how to fix it?
i have test it with unity text and unity text have no problem like this.
anyone can help?

Can you provide me with the specific text that you are using in the above example?

You may need to include the text in some text file and attach it to your post due to some weird anti spamming tool used on the forum.

Is it possible that this font does not include the ‘.’ character? If so you might need a fallback font to make up for it.

Also you can check if there is a warning about Ellipsis or Underline in your console because if ‘_’ and ‘…’ are missing then TMP seems to use some characters of your font to replace them.

Finally it might be a kerning issue though I’m not very confident about that. You can still verify that Kerning is checked in the Extra settings of your TMP object.

Just taking a guess at which dot character that OP used.

ブリタニー•ワイルド

ok, here it is.

did you mean “・” this interpunct ? i tried it with only " " (space) as divider, doing it alphabet instead of japanese but still the same.
but things i know if i make it like,

public string GetFullName
    {
        get
        {
            string fullName = "abc"+ " ・ " + "def";
            return fullName;
        }
    }

then it is work as i expected “abc ・ def”. seems like this happen because i referencing string from firstName & lastName.

i try to on and off all option in extra setting and still nothing changed.

7542127–931756–text example.txt (98 Bytes)

How about this?

[Serializable]
public class Character
{
public string firstName = "FirstName";
public string lastName = "LastName";

private string fullName;
    public string GetFullName
    {
        get
        {
            //I also has tried this(commented),
            //string fullName = String.Concat(firstName + " ・ " + lastName);
            //string fullName = String.Join(" ・ ", firstName, lastName);
            fullName = firstName + " ・ " + lastName;
            return fullName;
        }
    }
}

still not work :frowning:

[Serializable]
public class Character
{
public string firstName = "FirstName";
public string lastName = "LastName";

public string fullname;

private void joinname()
{
    fullName = firstName + " ・ " + lastName;
}
}

i also tried it with method instead of properties, call method, then get fullname but still not work.

i also add more pictures about my settings.
note: in the picture text work as expected because its in editor and not getting text by joining first and last name.

7542238--931783--11.png
7542238--931786--22.png

OK then what do you see in console:

[Serializable]
public class Character
{
public string firstName = "FirstName";
public string lastName = "LastName";

[System.NonSerialized]
public string fullName;

    public string GetFullName
    {
        get
        {
            fullName = $"{firstName} ・  {lastName}";
            Debug.Log($"fullName->{fullName}") ;
            return fullName;
        }
    }
}

result in picture.

i also tried few things and also tried unity text instead TMP then it works in unity text.
so i guess is this some bug from TMP it self?

I see only 2 possibilities: one is an issue with the serialization and the other an issue with the font file. But it may come from elsewhere.

I try to call it in another class like this

public void SetFullName(Character chara)
    {
        //instead using this,
        //nameText.text = chara.GetFullName;

        string firstName = "FirstName";
        string lastName = "LastName";
        string fullName;

        fullName = firstName + " ・ " + lastName;

        nameText.text = fullName;
      
    }

result must be, “FirstName ・ LastName” but in game it still overlapping

i also try to change the font with unity default font (LiberationSans) but still overlapping :frowning:

I think make a tiny project that shows the issue and send it as bug report. Maybe you will find the issue while doing so.

all this time i think the problem came from serialize or string assigning but
Finally, i found posting that actually be the answer of my problem.

the reason it’s overlapping is actually came when i read Text Asset and assign it in string firstname & lastname array.
thanks for your help :slight_smile:

1 Like