- Home /
.txt files diappear after build is done
I use .txt files in my game - they are located in .../Resources/Text/. I load them like this
private void LoadWallOfText(string file)
{
_lines = File.ReadAllLines(Application.dataPath + "/Resources/Text/WallofText/" + file + ".txt");
}
where _lines is a string array. After building the project I realized there was no text in the game, I checked output_log.txt and found out that the game can't see the Text folder, even though other resources like music and pictures work fine.
I handled this situation by pasting the whole Text folder to my build's Resources folder - and it works fine now. The only problem is that .txt files are now vulnerable to any changes from the users.
Is this a common issue? Is there a way to fix this?
Answer by syclamoth · Jan 24, 2012 at 01:51 PM
Instead of using File.ReadAllLines for this, you could store the text file as an asset, and use Resources.Load. This will allow Unity to package the file up into the build, and still use it like a loaded file.
Alternatively, if you have a public 'TextAsset' variable in your class, you can even assign the file in the inspector, the same way you would a texture or prefab.
public TextAsset text;
private string _lines;
void Start()
{
if(text)
{
_lines = text.text;
}
}
Right, all ressources are packed into the build. They aren't seperate files anymore. All stuff in the Ressources folders can only be accessed via Ressources.Load
.
If it's a standalone build, feel free to put the txt file in any directory you like (manually) and use System.IO
stuff.
Your answer
![](https://koobas.hobune.stream/wayback/20220613063333im_/https://answers.unity.com/themes/thub/images/avi.jpg)