- Home /
Problem loading XML files after build using .NET libraries
Hi,
I am reading some text from an external XML. Everything works fine in the editor, but when 'I build & run' is not able to reach the files.
Here are the messages I got in the player log related to the problems: IsolatedStorageException: Could not find a part of the path "/Users/Alvaro/Desktop/Dropbox/proyectos unity/alfa06/demo.app/Cofiles/victim.xml"
The way I code this is like this:
var writer:XmlWriter = XmlWriter.Create(Application.dataPath.Substring(0, Application.dataPath.Length - 6)+file,settings);
var reader : StreamReader = File.OpenText(Application.dataPath.Substring(0, Application.dataPath.Length - 6)+file);
Please I need some help... I am getting a bit nervous if I can't solve this :S
And I got to read this thread:
KennyW: I can read an XML file from my data folder without problem. But my question here is how will I be able to read an XML file from inside my Unity3D resources (i.e. in the "project" tab or project "Hierarchy" instead of a file path?
dreamora: you can't
if you drop it into the project it will cease to be an xml (it will no longer exist as file in the build but will be part of the sharedassets.dll file), it will become a text asset where you can get the string from but only that.
Thnks in advance
Answer by yoyo · May 05, 2011 at 05:47 PM
Application.dataPath only ends with "Assets" (6 characters) when you run in the Editor. You shouldn't strip anything from the dataPath, just use it directly, and move your Xml files under your Assets folder.
You probably want to put the Xml files into your Resources folder to make sure they get included in the build.
Thanks yoyo. Then how is that? If I don't put my X$$anonymous$$L in the Reources folder in the build will not be included? And how is possible that in the Editor works and then in the Build don't! How can I save the player progress?... Sorry yoyo, but I am a bit disappointed :(
@Uzquiano: did you read the page yoyo linked to? The docs already answer these questions.
@Eric,yes I read. Even I read before asking this question... I will have to think in a solution. $$anonymous$$aybe I was too much time getting nervous now... Now I get the point of the Resources floder, becuase it is a direct link that your build always knows... Thanks Eric
Any files in your Resources folder at the time you make a build will be included in that build. This is useful for assets which you will load dynamically but which are not referenced from your scene. $$anonymous$$ore information here -- http://unity3d.com/support/documentation/ScriptReference/Resources.html
Thanks yoyo, all this info I read sometime ago, but I got a wrong picture. Thanks agaim
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
How Load XML File in java? 2 Answers
Missing additional configuration xml files after build 0 Answers