I have a project that reads through an xml file and then starts a dynamic visualization of it. It all works great in my test plays in Unity, but when I build it and run it, it just sits there and does nothing. I suspect that it may not be reading the data file I’m trying to give it.
The script to input the data file is something like this:
var xmlFile : String;
function Start(){
ImportXMLReader();
}
function ImportXMLReader(){
// Get filepath and create an XmlReader
var xmlFilePath : String = "Assets/XML/" + xmlFile + ".xml";
var readerSettings : XmlReaderSettings = new XmlReaderSettings();
readerSettings.ProhibitDtd = false;
var xmlReader : XmlReader = XmlReader.Create(xmlFilePath, readerSettings); //read in xml file
etc…
So it is looking in the Assets/XML folder for the xmlfile. I can see why this would work in my project but not in the build, since there are not actual folders in the build. Is this what is going wrong and how would I fix this so the build can actually access the xml file. I’d prefer to include it right in the build, but I suppose if necessary it could be an external file?
Edit: I have now tried this approach with Resources.Load
var xmlFilename : String;
function ImportXMLReader(){
var xmlFile : TextAsset = Resources.Load(xmlFilename) as TextAsset;
var readerSettings : XmlReaderSettings = new XmlReaderSettings();
readerSettings.ProhibitDtd = false;
var xmlReader : XmlReader = XmlReader.Create(new XmlTextReader(new StringReader(xmlFile.text)), readerSettings);
etc.
I’ve put the xmlfile in a folder called Resources in my project. Unfortunately it still doesn’t work when I build it.