• 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 /
  • Help Room /
avatar image
0
Question by Reign_of_Light · Dec 13, 2016 at 08:22 PM · c#scripting problem

Force style of Application.persistantDataPath on Mac

Hi,

like probably most of you, I use Application.persistantDataPath for retrieving the file path my game saves its savegames to.
Now, I don't know why, but on Mac my savegames are written to the Library in the following manner: '~/Library/Application Support/unity.company-name.product-name/' . Unfortunately, this is a problem, since my client (a big publisher) requires me to save in the following location: '~/Library/Application Support/company name/product name' .

This shouldn't be a big deal, for the documentation on Application.persistantDataPath says: "In recent Unity releases user data is written into ~/Library/Application Support/company name/product name. Older versions of Unity wrote into the ~/Library/Caches folder, or ~/Library/Application Support/unity.company name.product name."

So, presumably - since I'm using a recent release of Unity [5.4.3f1] - Unity already should save into the desired location, but unfortunately it still saves into this weird unity.company-name.product-name/ folder, even on Macs that run my game for the very first time.

Do you know of any way to force my game to save its savegames into the folder ''~/Library/Application Support/company name/product name'' ?

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

1 Reply

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

Answer by UnityCoach · Dec 13, 2016 at 08:49 PM

Well, you may always retrieve the path using Application.persistantDataPath, then trim it and rebuild the path you want.

         if (Application.platform == RuntimePlatform.OSXPlayer) // check your on running a Mac build
         {
             if (float.Parse(Application.version) <= 6.7f) // check if older version of Unity
             {
                 string path  = Application.persistentDataPath;
                 Debug.Log(path);
                 char[] charsToTrim = {'/'};
             string [] splittedPath = path.Split (charsToTrim);
             path = "";
             for (int i = 0 ; i < splittedPath.Length-1 ; i++)
                 path += splittedPath[i] + "/";
             path += "CompanyName/Product Name";
                 Debug.Log(path);
             }
         }
Comment
Add comment · Show 4 · 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 Reign_of_Light · Dec 14, 2016 at 06:39 AM 0
Share

Wow, I really didn't think of that. Great answer and great piece of Code!!

avatar image Reign_of_Light · Dec 14, 2016 at 08:13 PM 0
Share

Okay, in the end it didn't work out. Using the custom path, I first got the error "IsolatedStorageException: Could not find a part of the path." . I managed to solve it by first checking and creating the custom directory using Directory.CreateDirectory(path). But, unfortunately, now I'm getting the error "UnauthorizedAccessException: Access to path ... is denied".

As it seems, one cannot save outside Application.persistentDataPath :( .

avatar image UnityCoach Reign_of_Light · Dec 15, 2016 at 09:55 AM 0
Share

Yeah, I forgot to mention it, but I'm afraid you can't just do what you want in the ~/Library folder. You can save to User folder, like Documents or desktop, but ~/Library is a touchy one. This is probably something you want to change in Xcode, but Unity builds the app bundle for you. There's some interesting stuff here on publishing apps to mac app store, that may help you.

avatar image Reign_of_Light UnityCoach · Dec 15, 2016 at 12:07 PM 0
Share

Greeeeeeeeaaaat!! I don't know yet if your link will help me solve that specific problem with saving (I will try!), but beside that it seems to contain a solution for another head-ache-inducing problem (or perhaps even for multiple problems) I had with the mac version. Thank you so much for pointing me to this manual-page!! Why didn't I look into the manual sooner..

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

283 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 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 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 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 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 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 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

Unity Freezes After SceneManager.LoadSceneAsync 2 Answers

[SOLVED]I'm trying to destroy a button. YOU MAY WANT TO CHECK THIS THREAD IF DESTROY OBJECT IS NOT WORKING FOR NO GOOD REASON. [SOLVED] 0 Answers

Accessing string from other script 1 Answer

PostProcessingFactory.cs 2 Answers

How do I add a simple jump function to this script? 2 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