Saving data on device

I am using XmlSerializer class to read and write objects into XML files.

Those XML files are located under Assets/StreamingAssets in my Unity project folder.

To read/write these files I am using the path:

Application.streamingAssetsPath + “/fileName.xml”.

But after built, on the desired device it does not work.

I also tried using Application.persistentDataPath but it doesn’t work either.

The application on the device is looking for a file destination which does not exist.

Try to look at the documentation for different path on device

Post the code that doesn’t work. If you don’t we can’t possibly hope to tell you what you’re doing wrong.

try dropping the slash,

Application.streamingAssetsPath + "fileName.xml

and if i remember correctly unity uses "" instead of “/”

(remember to escape them)

Both of those are wrong. (Please check the docs linked earlier.)

Dropping the slash is wrong.

I am using the following code to load the data:

playerContainer = PlayerContainer.Load(Application.streamingAssetsPath + “/Player.xml”);

which results in an error:

Non-fatal Exception: java.lang.Exception: IsolatedStorageException : Could not find a part of the path “/jar:file:/data/app/com.mygame.mygame-1/base.apk!/assets/Player.xml”.
at System.IO.FileStream…ctor(FileStream.cs:290)

The documentation says the Application.streamingAssetsPath automagically points to different locations depending on the platform type. So this function should be enough to suit my needs on any type of the destination platform.

The final .apk file actually contains the XML files in the “assets” folder, but the XML’s still cannot be loaded on the device as stated above.

I still don’t know what is wrong with it.