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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

TextAssets in Resources broken when converting to Unity 5?

Discussion in 'Scripting' started by TinyMobGraham, Apr 17, 2015.

  1. TinyMobGraham

    TinyMobGraham

    Joined:
    Oct 17, 2013
    Posts:
    38
    I'm going through the process of converting my 4.6.4 project to Unity 5. One strange problem is that all of my .txt, .xml and .json textasset files that are in various Resources subfolders are not being registered as actual text files in Unity 5. They worked fine in Unity 4.6.4 of course.

    So any code that is trying to load them with Resources.Load<TextAsset>() returns null in Unity 5.

    I tried re-importing them, this made no difference. The only thing that seemed to work was to duplicate them one by one in Unity (which adds a " 1" to the end of the file name), then copy them to the main /Assets/Resources/ folder, then rename them back to their original file name by removing the " 1". Suddenly Unity 5 sees them as proper text files now (the inspector shows their content). Then I need to delete the original file that exists in the original Resources subfolder and copy the "fixed" file in to take its place.

    I have no idea why this sequence of steps is necessary. Simply copying them to the main /Assets/Resources/ folder does not work. Likewise, simply duplicating them and renaming them in their original folders does not work either. I need to do both steps.

    My question is:
    1. why are these text assets broken in Unity 5?
    2. is there an easier way I can fix them without having to manually rename/move/replace each file (I have hundreds of these files to fix manually)

    Any more info/advice is greatly appreciated. Thanks!
     
  2. TinyMobGraham

    TinyMobGraham

    Joined:
    Oct 17, 2013
    Posts:
    38
    Has no one else encountered this problem? Any text file/asset that I make in my Unity 5 project has this problem and requires me to manually "fix" it by moving it to the main "Resources" folder, renaming it so it re-imports, and them moving it to its proper Resources folder location. Why?
     
  3. TinyMobGraham

    TinyMobGraham

    Joined:
    Oct 17, 2013
    Posts:
    38
    I'm still having this issue. Every time I upgrade Unity (this time to Unity 5.0.1p3) it breaks all of my text asset files that are not in the main Resources folder. The file symbol beside each of these files in Unity is just a white file that is unrecognized. If I then copy them to the main Resources folder and rename them so Unity looks at them again, then their file symbol turns to a lined paper and Unity sees them as proper text assets again.

    Is it because these files are in a Resources subfolder of StreamingAssets? None of this was a problem in Unity 4.6.4 and earlier. Am I the only one with this problem? I am using Mac OSX 10.9.5.
     
  4. TinyMobGraham

    TinyMobGraham

    Joined:
    Oct 17, 2013
    Posts:
    38
    The problem is definitely something to do with the StreamingAssets folder. Any text asset file I put in a Resources folder anywhere else works fine. However if I put a text asset in a Resources folder under StreamingAssets it is broken.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,797
    I think you might have answered your own question. Here is a quote from the StreamingAssets documentation:

    "Any files placed in a folder called StreamingAssets in a Unity project will be copied verbatim to a particular folder on the target machine."

    That means they are not imported as text assets. You would need to open them and read them as text files directly if they are in StreamingAssets.

    Documentation here:

    http://docs.unity3d.com/Manual/StreamingAssets.html
     
  6. TinyMobGraham

    TinyMobGraham

    Joined:
    Oct 17, 2013
    Posts:
    38
    Yes that is correct. However this all worked fine in Unity 4 and earlier (that documentation hasn't changed for Unity 5). Also, once I "fix" the text files they still work fine in the StreamingAssets folder, it's just Unity doesn't seem to import them correctly on its own.