Search Unity

  1. Unity 2020.1 has been released.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Creating folders and files

Discussion in 'Getting Started' started by progamer12710, Jul 28, 2020.

  1. progamer12710

    progamer12710

    Joined:
    Jul 14, 2020
    Posts:
    2
    I was trying to make a game that is going to read some stuff from a txt file. My goal is that i want to be able to put files in the folder from an ingame editor or external sources. One of my problems is that i don't know how to make a dedicated folder that i can easily find and open in the windows explorer. The other is that i dont know how to create a new file txt in that specific folder.

    Any code examples are appreciated.
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    8,758
    Generally you'l want to use either the persistent data path or the streaming assets folder, depending on if any of these text files need to originate with the build and what platform you are targeting.

    https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
    https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html

    But Unity can do any regular C# file access stuff (see any C# tutorial or forum thread on reading/writing text files, doesn't need to be Unity related), so on target platforms which aren't locked down the folder can be wherever you want really. Mobile and WebGL are extremely limited here, while Windows/Mac/Linux you can do anywhere so long as the user's account has access to the folder.
     
    progamer12710 likes this.
unityunity