At the moment, my game can open up an XML file inside the editor when I run it. In my XMLReader.cs I'm loading in my file like so:

_xmlDocument.Load(Application.dataPath + "\\HV_Settings\\Settings.xml");

This class also deals with what the XML should do once it has been read in.

However, when I build the game and run the exe, this file isn't called. I know that I can store this file in the C drive, but I want to keep everything in one place so when I start to release what I'm working on, the user doesn't need to do anything.

Am I doing something silly which is causing the XML not to be read?


Instead of going for the manual copy solution, you can opt to go for the StreamingAssets route.

Create a folder within your Unity project named "StreamingAssets" and place your XML files in there. Upon build, Unity will then create a verbatim copy of this directory. Your XML files will be accessible at string path = Application.dataPath + "/StreamingAssets";


To load files on runtime you must use the Resources class. After placing your file inside a folder called "Resources" try something like this:

TextAsset propStoreTextAsset = (TextAsset)Resources.Load("resourcename", typeof(TextAsset));

Please note, that a TextAsset is not mutable.

  • \$\begingroup\$ Why the downvote? I mentioned the Resources folder, which is the accepted answer. \$\endgroup\$ – jonas Nov 30 '12 at 12:15

StreamingAssets alternative (cross-plateform):

public static string BundleFilePath(string filename) {
    string result;
    result = Path.Combine(string.Format("file://{0}", Application.streamingAssetsPath), filename);
    result = System.IO.Path.Combine(Application.streamingAssetsPath, filename);
    #elif UNITY_IPHONE
    result = System.IO.Path.Combine(Application.dataPath, string.Format("Raw/{0}", filename));
    result = System.IO.Path.Combine("StreamingAssets/", filename)); // untested
    return result;

Found a work around:

When I build my project, I need to manually drag my XML file into the Resources folder Unity create in the Game_Data folder when it builds the exe.

  • \$\begingroup\$ Technically this works, but it's quite easy to have Unity include the file automatically so that you don't have to remember to do this every build. \$\endgroup\$ – jhocking Jan 21 '14 at 21:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.