- Home /
TextAsset read non txt files
Hi, I have unrecognised extension of the file (any but not .txt), but i want to use that in StreamReader. I also want to add that file trough Unity's inspector, via public variable. Is there any way to do it? Is there any other variable type that I could use, instead of TextAsset ?
Thank you.
Answer by Lauris48 · Jun 07, 2019 at 07:47 AM
Found answer here: https://answers.unity.com/questions/1351604/is-it-possible-to-reference-a-custom-file-type-in.html
I guess my best solution is to rename these files to .txt
If something isn't text it's best to add the extention .bytes
Answer by Pangamini · Jun 07, 2019 at 08:41 AM
You can read files normally using System.IO.FIle class. You are not limited to any Unity tools for working with files. The TextAsset is what it says - an asset. It uses unity references, derives from UnityEngine.Object. It has nothing to do with file access, and it won't be present as a file in the build. The usual location for files that you want preserved in their original binary form in the build is the StreamingAssets folder. You can get the folder path by using Application.streamingAssetsPath and store any files that should be part of the build here. But you can also load any files from any location where the OS gives your app an access permission.
I use StreamingAssets for storing my custom config files and savegame files, and generally anything that can be changed during the game and written back to be preserved between app runs
Answer by alakoring · Apr 29, 2020 at 10:15 PM
According to https://docs.unity3d.com/Manual/StreamingAssets.html, “On many platforms, the streaming assets folder location is read-only.” Sounds like a bad place for save files!
As for configuration files, my current thought is to avoid this because players can find and change them. Text assets aren’t exposed in the same way.
Which is why it would be super useful if there were a way to use arbitrary extensions as text assets (.lua in my case)…
Your answer
![](https://koobas.hobune.stream/wayback/20220612202757im_/https://answers.unity.com/themes/thub/images/avi.jpg)