Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Jessespike · May 18, 2016 at 08:05 PM · windowsfilesave data

Write/Read save files on Windows: MyDocuments vs persistentDataPath

I keep reading that all saved data should be located in Application.persistentDataPath, which makes sense for code to be cross-platform compatible. But many games for Windows will save their game saves to MyDocuments/"GameName". I suppose this makes it easier on the user to locate and backup if they wanted.

Is it appropriate to save player data to MyDocuments for Windows and use persistantDataPath for other platforms? Are there any reasons why I should or shouldn't use MyDocuments to store data or is it simply based on the developer's preference?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Dave-Carlile · May 18, 2016 at 08:15 PM

For windows, "My Documents\My Games\YourGameName\" comes highly recommended. Don't save directly in the My Documents folder because it dirties it. Many games use My Games.

I would suggest using the .NET Environment.GetFolderPath method to get the My Documents folder. I don't believe there's an option to return "My Games" using that unfortunately, but you can get close at least.

Here's what I'm using. Builds the My Games path when compiled for Windows, otherwise uses persistentDataPath. At some point the plan is to use whatever game folder is standard for other platforms, assuming there is some standard method for finding that path.

 using Environment = System.Environment;

 #if UNITY_STANDALONE_WIN
         savedGamesPath =
            Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments).Replace("\\", "/");
         savedGamesPath += "/My Games/MyGameName/";
 #else
         savedGamesPath = Application.persistentDataPath + "/";
 #endif


Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by FortisVenaliter · May 18, 2016 at 08:10 PM

Part of it is developer preference, yeah, but part of it is also ease of coding. For example, if you code it to always go to My Documents, you need to manually handle problems with file/folder permissions, whereas the persistent data path is safe in that manner. Also, remember that users can have multiple folders link into their libraries (of which Documents is one), so that may further complicate matters. Finally, I believe the persistent data path is user-agnostic... e.g. you can access it from any Windows user, but the documents folder is obviously limited to the user.

Many games not built with Unity will just store to the My Documents folder because they don't have a built-in manager for that, so they have to write their own code, and My Documents is the obvious location.

So, if you're a beginner, it's probably best to just use the built in functions so you don't have to worry about all the extra stuff. If you're up for the challenge, though, anything is possible.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jessespike · May 19, 2016 at 08:10 AM 0
Share

Thanks for the detailed response, I really appreciate it.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

42 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Open custom file type 1 Answer

Windows 8 - Windows.Storage WriteTextAsync exception 0 Answers

When writing a txt file, it says sharing violation 3 Answers

Access is denied in Windows 8 App 0 Answers

Standalond built for Windows doesn't include text assets 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges