- Home /
How to Create Files on Players Computer?
I know that you can create and write to files in Unity. I believe the Application.dataPath while in the Unity editor will create the files in the Assets folder. However, when the game is built where will these files be created so that I can guide the player to them. Windows and Mac?
Answer by aFeesh · Aug 28, 2019 at 08:21 PM
Take a look at Application.persistentDataPath this details the paths for each platform.
Answer by Bonfire-Boy · Aug 29, 2019 at 10:39 AM
Application.dataPath is generally not a sensible place to save things at runtime, since a) its location varies and b) doing so in the editor introduces a new asset to your project. In the editor it is the Assets folder of your project, whereas in a build it will vary with the platform, and not necessarily be writable. See https://docs.unity3d.com/ScriptReference/Application-dataPath.html for details
If as the question suggests, you're building only for desktop platforms, then you can save things where you like (so long as the filesystem gives the user permission to do so).
With some kinds of build (eg mobile, windows store app), you're limited as to where you can save things - they need to be under Application.persistentDataPath as mentioned in Time_flys answer. There's no such restriction for standalone builds - you can for example let the user choose somewhere that's convenient to them.