Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Difficulty with word wrapping in text mesh with Japanese fonts

Discussion in 'Editor & General Support' started by littleblue666, Feb 27, 2020.

  1. littleblue666

    littleblue666

    Joined:
    Jul 31, 2017
    Posts:
    7
    I'm working on the multi-language support for my game. Text in my game uses textmesh objects and the wordwrap is performed by this function (since textmesh does not allow you to define a width and use wordwrap by default).

    Code (CSharp):
    1. public static void TextWrap(TextMesh tm, string textbody, float howwide)
    2.     {
    3.         string[] parts = textbody.Split(' ');
    4.         string tmp = "";
    5.         tm.text = "";
    6.         for (int i = 0; i < parts.Length; i++)
    7.         {
    8.             tmp = tm.text;
    9.             tm.text += parts[i] + " ";
    10.             if (tm.GetComponent<MeshRenderer>().bounds.extents.x > howwide)
    11.             {
    12.                 tmp += "\n";
    13.                 tmp += parts[i] + " ";
    14.                 tm.text = tmp;
    15.             }
    16.         }
    17.     }

    It works fine, everything looks right, but I noticed with Japanese characters, when I switch my project's language setting to Japanese, the word wrap simply does not work. The text just prints out left to right and keeps going right without any line breaks that should be inserted by this function. The word wrap function works with every other type of font I've tried, including Russian and Korean. But with any Japanese font I've tried, it simply does not work.

    I do not speak Japanese, for testing my localization scripting I use google translate.

    I know this may be hard without more information, but could anyone hazard a guess as to why all of my fonts/languages work properly with this word wrap function, but Japanese does not?
     
    Last edited: Feb 27, 2020
    CiberX15 and kent_slg like this.
  2. CiberX15

    CiberX15

    Joined:
    Jul 31, 2013
    Posts:
    15
    Sorry to necro this thread but I am having the same issue and it is not limited to text mesh. Normal UnityEngin.UI.Text does not properly wrap Japanese either.