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

Resources.Load() as TextAsset does not load spanish text

Discussion in 'Scripting' started by georgeq, May 10, 2016.

  1. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    I have this simple line:

    TextAsset lngr = (TextAsset) Resources.Load("Text\info");

    It works fine except for the fact that Spanish characters like "ñ" or "á" are skipped, for example; the file contains the word "Capítulo" but it is loaded as "Captulo", is this a bug? or am I missing something?

    At first I thought it was a font's problem, but when I debugged the code I realized it was caused by Resources.Load

    I'm using Unity 5.3.4 personal edition.
     
  2. georgeq

    georgeq

    Joined:
    Mar 5, 2014
    Posts:
    662
    After several attempts I finally found a work around, hope someone can benefit from it. If you have text in any European language (other than English), don't save your text file as ".txt" instead save it as ".bytes" and do the following:

    using System.Text
    .
    .
    .
    TextAsset lngr = (TextAsset) Resources.Load("Text/info");
    string txt = Encoding.UTF7.GetString(lngr.bytes);
     
    Kuraqen, xavierboy89 and Valquiria7 like this.
  3. Andreas_Knauf

    Andreas_Knauf

    Joined:
    Apr 10, 2017
    Posts:
    1
    Hi. I had the same problem with different languages and Resources.Load.
    The problem is the coding of the textfile. Normally the Windows-Texteditor (and many other Textprograms) saving textfiles as ANSI.
    The only thing you have to do is to save the textfile as UTF8.
     
    nd2k7 likes this.
  4. Kuraqen

    Kuraqen

    Joined:
    Jul 10, 2018
    Posts:
    1
    What a god <3