Search Unity

Bug TextAsset causing Unable to Parse File error

Discussion in 'Editor & General Support' started by ghostaegis, May 5, 2021.

  1. ghostaegis

    ghostaegis

    Joined:
    Dec 1, 2016
    Posts:
    19
    The attached text asset file is throwing the following error in the editor, preventing builds (it's a JSON file stored as a text asset that holds the subtitles for a cutscene).


    Unable to parse file Assets/0_Scenes/Final/Menus/04-CanyonEntry-converted.asset: [Parser Failure at line 12: Expected closing '}']

    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)


    It's generated by a custom editor tool that takes plaintext story script files and converts them into the JSON formatted files per-scene. All of the files throw this error now.

    It's really easy to reproduce, just add the file to a project, and every time you reimport it, it will throw the error.

    Prior to updating from 2019 LTS to 2021.1.x these files generated by the import tool worked fine. Now they don't and I can't really even begin to figure out why. Am I missing something obvious? Or is this a bug?
     

    Attached Files:

  2. ghostaegis

    ghostaegis

    Joined:
    Dec 1, 2016
    Posts:
    19
    This is still happening on 2021.1.6. It's basically made the entire cutscene pipeline unusable, and I can't seem to find a workaround. I filed a bug report but haven't had a response. Has anybody with a similar problem been able to figure something out?
     
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    Pretty sure you cannot use .asset file extension for your own JSON stuff... that extension is recognized by Unity as a standard asset serialized as YAML and it tries to parse it and chokes because it isn't YAML.

    Does the error go away if you name the file instead with .json or .txt ? Those are two of the approved TextAsset extensions. There may be others.

    NVM: looking at your file it looks like it embedded JSON into a field in the YAML file. But I'm not sure what kind of asset file that is because it looks like it is missing its identifier GUID.
     
    Last edited: May 12, 2021
  4. ghostaegis

    ghostaegis

    Joined:
    Dec 1, 2016
    Posts:
    19
    Yeah it's bizarre. Well your response actually helped quite a bit, the way I was doing it was based on part of the documentation around using AssetDatabase.CreateAsset for text-based files. But it's obviously a bit of an odd approach. So I switched to using System.IO File.WriteAllText to create an actual .json file and reworked the tool around that instead. Bypasses the problem entirely.

    Something seems glitchy with AssetDatabase.CreateAsset. If anyone else runs into a similar problem, try to use the File methods instead of the AssetDatabase methods if you can.
     
  5. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,736
    Interesting... TIL! I'd never done that. If you just drop a text file into the project it can be loaded AS a TextAsset, but I suppose that implies that one could actually create a "TextAsset" as you have done.

    Either way, just a reminder that you can't use good old System.IO stuff in the build but I'm guessing you know that. It's fine for editor tools obviously. Remember to call AssetDatabase.Refresh() call after you write the file!
     
  6. ghostaegis

    ghostaegis

    Joined:
    Dec 1, 2016
    Posts:
    19
    Thankfully it's just an editor tool in my case, so no big deal. Haha yes thanks for the refresh reminder, I almost never use System.IO and was baffled why the new asset took so long to show up. All fixed now!
     
    Kurt-Dekker likes this.