Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Can I update a XML file during runtime in my Unity build?

Discussion in 'Getting Started' started by multix, Sep 13, 2015.

  1. multix

    multix

    Joined:
    Aug 5, 2013
    Posts:
    16
    Hi,

    I am quite new to Unity and asking you for some kind of validation of my idea:

    - I want to build my Unity game as normal, but also a XML file with data is part of the build and in the normal application data path saved
    - Now I want to update that XML file with more current data during runtime of my game (e.g. read data from a PHP database in the web via option menu in my application)
    - Question: Can I overwrite my prexisting XML file with the new data read?

    Is that an issue and/or what do I need to worry about that approach? Because just for updating I dont want to release all the time a new version in the appstore. I also heard about asset bundles but is there some more easy way with my approach above?

    Thanks and regards,
    multix
     
  2. superpig

    superpig

    Quis aedificabit ipsos aedificatores? Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,215
    While it's quite easy to get the XML file to be embedded in your build - I'd use the StreamingAssets folder - you will probably not be able to change it at runtime, because on most platforms you do not have write access to your application files.

    What I suggest you do is to ship the XML file with your application, but when you download a new version from your server, save the new version in the user's writable area (e.g. Application.persistentDataPath). Then, when your game is starting up, you check there first to see if an updated XML file is present, and if not you 'fall back' to the version that you shipped with the app.

    Alternatively, you might just want to pull the data from something like Unity Cloud Data.