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. Dismiss Notice

Resolved Keep data files in build, but be able to modify them from the app?

Discussion in 'Editor & General Support' started by EDartBlade, Aug 17, 2023.

  1. EDartBlade

    EDartBlade

    Joined:
    Oct 27, 2019
    Posts:
    4
    Hey there!

    The title might be slightly confusing, sorry about that, I just don't know how to condense this into one question.

    What I'm trying to do is that I have data files in my assets folder (basically baked data) and I want them to be in the build, but I want the user to be able to overwrite (rebake) these files if they choose to, directly from the app. Is it possible to write to the contents of the assets folder after the app has been built? Or should I work around the problem?
    One way I thought about working around it is to copy these files into the persistentDataPath on the first startup, and read from there when needed. I would like to avoid having to bake these files on the first startup, because it can take quite a while.

    Thank you!
    - Alexa
     
  2. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    9,900
    Why isn't the standard way feasible in your case?
    - check if you have a file X in your
    persistentDataPath
    , if you have, load that
    - if you don't have X, then load the file X you have embedded in your assets, use that
    - bake any user data in the
    persistentDataPath
    in your file X

    AFAIK
    File.Exists
    work on most platforms in the
    persistentDataPath
    context.
     
  3. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    5,769
    This how 99% of games and other applications work.
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,563
    Isn't this analogous to how Minecraft does its save world?

    I seem to remember the save state was just the delta changes to the underlying random-seed-generated world within a given chunk.

    This seems to support that:

    https://minecraft.fandom.com/wiki/Chunk_format

    The seed gives you the unmodified world rapidly (perhaps cached).

    The deltas say what has happened to it.

    If it's good enough for minecraft...
     
  5. EDartBlade

    EDartBlade

    Joined:
    Oct 27, 2019
    Posts:
    4
    Alright then I'll do that then!

    Thanks for the help!
    - Alexa