Search Unity

Question Saving and loading from a text file

Discussion in 'Asset Importing & Exporting' started by maaitamalek, Nov 3, 2022.

  1. maaitamalek

    maaitamalek

    Joined:
    Aug 25, 2019
    Posts:
    3
    I have a csv(text file) in my assets folder and I want to be able to save data in it and read from it I thought this would be easy but I've been looking for a solution for days now
    The closest thing I found was using streaming assets folder and unity web requests which works in the editor but when I build for Android it doesn't find the directory

    If someone could give me a step-by-step example of how to do this I would be very grateful
     
  2. bastien_humeau

    bastien_humeau

    Unity Technologies

    Joined:
    Jun 14, 2017
    Posts:
    191
    Hi there,
    Are you trying to read and write that file at runtime in your game? Or is the writing part just for editing in the Editor?

    If you're looking into runtime writing, you can't do it directly on the asset, because everything installed from the built application is read-only (you don't want players to be able to modify your game files directly).
    However, you can use
    Application.persistentDataPath
    that will give you a path to a local folder you can read and write to from the player.
    What you can do then, is try reading that file from the Application.persistentDataPath folder, and if it doesn't exist, then it's probably the first time the user is starting the application, so you can read your built-in version from the StreamingAssets folder and copy it into the persistentDataPath to be able to modify it.
     
  3. maaitamalek

    maaitamalek

    Joined:
    Aug 25, 2019
    Posts:
    3
    would you mind showing me how
    because I cant access the streaming assets folder in android