- Home /
Where to put my text files when exporting a project
I have a unity application I've just exported. The application does a lot of reading from text files found in ~/assets/data but these don't seem to be part of the .unity3d file that exports. Where should I stick these files in order for the web version of the application to access them?
They should remain in the project if you put them in Assets/Resources. But I'm surprised they are not available. Are you accessing them through file i/o or are you using the TextAsset class?
I use 'System.IO' $$anonymous$$y filepath takes a searchfield term and composes the directory path: filepath = "./assets/data/" + searchfield.Search + ".txt";
I doubt this will work for any form of compiled build. You have a few choices. You can convert your 'System.IO' code to use the TextAsset class. If the files aren't huge, you can statically link them in, or you can place them in the Resources folder and do a Resources.Load() to pull them as you need them.
Or you place them outside your project. On web builds, there are restrictions on what files you can access. I don't know if you can use 'System.IO', but I believe you can use the WWW class for files that live on your server.
Answer by unormal · Feb 27, 2013 at 12:44 AM
It is easiest to load text assets this way:
TextAsset Asset = Resources.Load("Data/Blueprints") as TextAsset;
Asset.text then contains the file data.
Note that you should not use the extension (in this case the actual file is Blueprints.xml). You must also use only .txt and .xml extensions, otherwise unity will not include them in the file.
...or .html, .htm or .bytes as pointed out by Eric5h5.
That's not really the easiest way. The easiest way is just to make a public variable, then drag'n'drop. That's also less brittle, since you can rename/move assets to your heart's content without breaking anything, while avoiding the usage of strings, plus it allows Unity to only include assets in a build that you're actually using.
Yeah, that's true if you're working with data inside of game objects. I was presu$$anonymous$$g he was using 'pure' code management objects/singletons, which is how I tend to work with large textual asset data. However, if you're working with game objects, you're certainly right.
Answer by unormal · Feb 27, 2013 at 12:45 AM
Make sure the extension is either .txt or .xml, and that they are in the resources folder. Unity won't drag along text files that aren't named .txt or .xml.
yeah they are saved as txt files, they still dont carry over
Your answer
![](https://koobas.hobune.stream/wayback/20220613093444im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Load and save text from web server 2 Answers
Parse an online text file 1 Answer
Cannot edit text file. 0 Answers
Iphone: How to read a file created by another application ? 1 Answer
Loading TextAsset returns null 1 Answer