So, I have this little issue where I outsmarted myself (I think).
I’m trying to load in XML files via these variables here.
private static string wepDoc = "Assets/Resources/XML/Equipment/Weapons/weapons.xml";
private static string armDoc = "Assets/Resources/XML/Equipment/Armors/armors.xml";
private static string shdDoc = "Assets/Resources/XML/Equipment/Shields/shields.xml";
But after building the project nothing is shown in their respective displays (probably because these paths don’t exist after a build).
So my question is: is there a specific path I should set to ensure that I can load in an XML file from, say, the data folder of a windows build? If I have to put the XML file into some specific location, that’s fine too.
And, for bonus points, if I need to do anything special or different to ensure that it works on (say) both Windows and Mac.
Double bonus points if the solution turns out to be something incredibly simple.
Technically speaking this wasn’t really “solved”, but I got the answer I was looking for, which is: you can’t make Unity load an External XML file after the game is built.
For those curious, my issue of not being able to read the XML files in the build was because I used LoadAssetAtPath as my loading method (which I assume didn’t work because it no longer found that file in the folder after the build). Switching the XML reference to
private static string wepDoc = "XML/Equipment/Weapons/weapons";
And the loading method to
public static void readAndPopulateWeaponsList(List<WeaponCore> equipList, string filePath)
{
XmlDocument xmlDoc = new XmlDocument(); // xmlDoc is the new xml document.
TextAsset textAsset = (TextAsset)Resources.Load(filePath, typeof(TextAsset));
xmlDoc.LoadXml(textAsset.text);
XmlNodeList equipsList = xmlDoc.GetElementsByTagName("weapon");
(etc...)
}
Fixed my problem.
When Unity makes a build, all the assets get baked into binary files which are fast to load. All the folders and files you have in the project in the editor don’t exist any more. It’s like baking a cake, and then asking where the egg that was on the side is now.
Use Resources.Load() to load the XML files as Text assets.