Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Loading a file with a custom extension as a TextAsset

Discussion in 'Addressables' started by Firewolf34, Feb 6, 2019.

  1. Firewolf34

    Firewolf34

    Joined:
    May 14, 2013
    Posts:
    6
    Perhaps this is not the right subforum to post this in, as I realize the Addressable Assets System is based on the underlying Unity Asset Database and how it interprets files... but I have a similar issue while using the AAS to @MaxBowser in his thread here: https://forum.unity.com/threads/loading-scriptableobjects.622075/

    When I try to load a text file with a custom extension (they are actually a custom Class serialized into JSON and written to disk, marked as Addressable) using this form:
    Addressables.LoadAssets<TextAsset>("Assets/BlockConfigs/Default.bconfig", null).Completed += onLoadHandler;

    I get a bunch of nulls back in the onLoadHandler Result array, because Unity does not see these files as TextAssets. I need Unity to interpret my file as a text file, and load it as a TextAsset, despite it's non-txt extension. Is there any way I could get the Addressable Assets system to help me with this? Perhaps by using a Resource Handler or something?

    Here's what my AddressableAssets database currently looks like, as you can see only two objects exist:


    Everything works fine when the extension of these files end in ".txt", but the system returns nulls if they have my custom extension.

    As you can see, they are pretty simple UTF-8 formatted JSON text files:

    Code (CSharp):
    1. {
    2.     "renderables": {
    3.         "renderable0": {
    4.             "instanceID": 6316
    5.         },
    6.         "renderable1": {
    7.             "instanceID": 0
    8.         },
    9.         "renderable2": {
    10.             "instanceID": 0
    11.         },
    12.         "renderable3": {
    13.             "instanceID": 0
    14.         },
    15.         "renderable4": {
    16.             "instanceID": 0
    17.         }
    18.     },
    19.     "castShadows": false,
    20.     "receiveShadows": false,
    21.     "renderableGroup": {
    22.         "i0": 0,
    23.         "i1": -1,
    24.         "i2": -1,
    25.         "i3": -1,
    26.         "i4": -1
    27.     }
    28. }
    Thanks in advance for your help!!

    Here's the script I used for testing this, if you're interested (it's very short):
    https://pastebin.com/Rn8m826i
     
    Last edited: Feb 6, 2019
  2. kleicht

    kleicht

    Joined:
    Aug 1, 2018
    Posts:
    7
    According to the manual:
    "The supported text formats are:

    • .txt
    • .html
    • .htm
    • .xml
    • .bytes
    • .json
    • .csv
    • .yaml
    • .fnt
    "
     
  3. Firewolf34

    Firewolf34

    Joined:
    May 14, 2013
    Posts:
    6
    Oh, nice. I suppose I can just use JSON extension then. Thanks!

    I would still appreciate if anyone had any info about how to do a custom extension though, if anyone knows a way. I did look into the whole Custom Importer experimental stuff, didn't work for my use case though (can't create TextAssets like that). But thanks again, man.
     
  4. pointcache

    pointcache

    Joined:
    Sep 22, 2012
    Posts:
    500
    you can use scriptable asset importer and convert the file to textasset on import. Not sure that it will work with the whole pipeline, but its going to be an actual asset.