• 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 RealMTG · Oct 09, 2014 at 02:42 PM · savepath

Computer documents path?

Hi!

I need to save a file to the players computer and I want it to save in Documents/Custom Levels. But I don't know how I would get this to work. I also don't know how I can get it to save on Mac since it appears to have a different path then Windows. But I still need help with Windows.

If you know these paths, please tell me!

Thanks

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
3
Best Answer

Answer by ExtremePowers · Oct 09, 2014 at 03:09 PM

In the top of your file put:

 import System.Environment;

Then try this:

 var DocumentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
 Debug.Log(DocumentsPath);

NOTE: The above is javascript

C#:

 using System.Environment;
 
 String DocumentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
 Debug.Log(DocumentsPath);


Comment
Add comment · Show 2 · 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 XxSimBaaxX · Jul 19, 2017 at 12:47 PM 0
Share

how can I get the path with the "/" separator and not the "\" separator?

avatar image RinkWilbrink XxSimBaaxX · Jan 25, 2021 at 05:36 PM 0
Share

The / or \ separator doesn't change anything, if you want it to be consistant you could add a @ before the string like: @"C:\folder\subfolder". what you could also do is string.Replace('\', '/') but this costs cpu performance and as I said before this doesn't change anything about the functionality so I would personally recommend to not use string.Replace.

avatar image
1

Answer by dmg0600 · Oct 09, 2014 at 03:11 PM

Doing a short search I could find this code from Apache in Unity forums:

 string path = "";
 
 if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) {
     path = Environment.GetFolderPath (Environment.SpecialFolder.LocalApplicationData);
 } else {
     path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
 } // if
 
 return path;

And combining it with this link from MSDN you can have it to write to My Documents in Windows and to Personal in Mac.

 string path = "";
 
 if (Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor) {
     path = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
 } else {
     path = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
 } // if
 
 return path;


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

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

32 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

Related Questions

My text document is updating twice when its only supposed to once 2 Answers

Saving current scene in another scene during gameplay? 1 Answer

How to Save PNG in android...? 1 Answer

Save path of navigation 1 Answer

Unlit Rendering Path for UI? 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