TextAsset vs StreamReader

public class XMLParser {
private string docName = @"/ArtifactExampleXML.xml";
private string inputLocation = Application.dataPath;

public XMLParser(){
	inputLocation += (@"/Resources"+docName);

public List<Artifact> Deserialize(){
	XmlSerializer xmls = new XmlSerializer(typeof (List<Artifact>));

	TextReader tr = new StreamReader(inputLocation);
	List<Artifact> artifactList = (List<Artifact>)xmls.Deserialize(tr);

	return artifactList;


This is the only way I could figure out how to Deserialize my xml file from within a folder in Unity. So this works fine when I hit play to do a test run, but when I build it for a WebPlayer and run through it I can see that it’s not reading the xml file.

I’ve seen people suggest to load it as a TextAsset, but from there I can’t figure how to get my data out of it. How can I load it as a Streamreader so I can just Deserialize it?

There is no local file IO when making a webplayer. You can load the file from a server, but not locally. The text in a TextAsset is just that:

public TextAsset myText;

void Start () {
    string contents = myText.text;

After more testing, turns out Application.dataPath is protected and can’t be accessed outside of Unity (or something like that, it’s a security breach to allow access to it, at least how I was calling it upon class initiation).

So that was the problem. When I put the xml in a resources folder and and loaded it as a TextAsset then deserialized it I was able to deserialize it just fine.