Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Saving data on device

Discussion in 'Scripting' started by yahretzkee, Mar 2, 2017.

  1. yahretzkee

    yahretzkee

    Joined:
    Dec 6, 2016
    Posts:
    13
    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.
     
  2. Deleted User

    Deleted User

    Guest

  3. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Post the code that doesn't work. If you don't we can't possibly hope to tell you what you're doing wrong.
     
  4. vothka

    vothka

    Joined:
    Mar 27, 2015
    Posts:
    59
    try dropping the slash,

    Application.streamingAssetsPath + "fileName.xml

    and if i remember correctly unity uses "\" instead of "/"

    (remember to escape them)
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,744
    Both of those are wrong. (Please check the docs linked earlier.)
     
  6. yahretzkee

    yahretzkee

    Joined:
    Dec 6, 2016
    Posts:
    13
    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.