Loading a text file from asset bundle

Have been looking into asset bundles recently and so far have succeeded in making downloadable content including new unity scenes, extra characters and so on. But I’ve come across a point where I want to load information from a text file in a bundle [namely for loading and reading specific character data.]

So far I can load the text file as an object but not in a way that I can open it with the streamwriter/streamreader.

Object charDataFile = bundle.LoadAsset(“dataFile.txt”);

I would like to open this file or maybe find a suitable filepath to the object where I can open it directly and examine each individual line.

Any suggestions? When I have more time I planned to research this but I thought I would check with the community first.

Just try casting it as a text asset, like this:

TextAsset charDataFile = bundle.LoadAsset("dataFile.txt") as TextAsset;

Then you can get the whole text as a string with it’s text property or get it as a byte array with the bytes property. If it is a JSON string you could deserialize it right away into your data class to read it’s properties.

If you need to read line by line you could parse it like this:

string[] linesFromfile = charDataFile.text.Split('

');

P.S. You should always try to research first before going to the community :stuck_out_tongue: