Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
add comment

3 Answers

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
add comment
up vote -1 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 at 21:14
add comment

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
add comment

Your Answer

 
discard

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.