Search Unity

Problem loading text asset

Discussion in 'Scripting' started by eyals, Mar 17, 2018.

  1. eyals

    eyals

    Joined:
    Jul 25, 2016
    Posts:
    4
    I am using Unity 2017.2.0f3 on Windows 10.

    I have a very simple piece of code which loads very short text files from the resources folder.
    It usually works, however 10% of the files load as blank strings.
    No error is thrown, no null pointers returned, but the text field is an empty string.
    The strange part is that when I look at the "bytes" field of the text asset, I see that all the bytes have been loaded correctly, but the "text" property is empty string.
    What is stranger, is that I cannot find anything special about the files, They start with normal english Ascii characters. And as mentioned, most files load just fine. It's just approxamtely 10% that do not.

    Code (CSharp):
    1. private void playDialog(string dialogName)
    2.     {
    3.         var currentClip = Resources.Load<AudioClip>(dialogName);
    4.         var textResource = Resources.Load<TextAsset>(dialogName);
    5.         var currentDialogText = textResource.text;
    6.         //....
    7. }
    and pay close attention to textResource.bytes in the debugger. The Ascii codes are correct! The file was loaded. But somehow ".text" (on the bottom) is empty (but only for some files)

    - textResource "" UnityEngine.TextAsset
    + base "" UnityEngine.Object
    - bytes System.Byte[21] System.Byte[]
    [0] 84 System.Byte
    [1] 104 System.Byte
    [2] 101 System.Byte
    [3] 121 System.Byte
    [4] 146 System.Byte
    [5] 114 System.Byte
    [6] 101 System.Byte
    [7] 32 System.Byte
    [8] 101 System.Byte
    [9] 97 System.Byte
    [10] 115 System.Byte
    [11] 121 System.Byte
    [12] 32 System.Byte
    [13] 116 System.Byte
    [14] 111 System.Byte
    [15] 32 System.Byte
    [16] 115 System.Byte
    [17] 112 System.Byte
    [18] 111 System.Byte
    [19] 116 System.Byte
    [20] 44 System.Byte​
    text "" System.String​
     
    Last edited: Mar 18, 2018