Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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";

share|improve this answer

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.

share|improve this answer
Why the downvote? I mentioned the Resources folder, which is the accepted answer. – 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;
share|improve this answer
up vote -3 down vote accepted

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.

share|improve this answer
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. – jhocking Jan 21 '14 at 21:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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