Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 junctioniv · Aug 18, 2014 at 08:08 PM · c#playerprefssave

PlayerPrefs - Can I save more than one?

Hey Unity Answers,

I am a c# dev that has recently started working with a small local indie game company. They have brought me on at the end of their game dev. cycle to help them shore up a few things, as the entire game was made without having a programmer on board.

The game currently tracks all the variables in playerprefs and saves them on exit, resets them on new game, and loads the previous game sate on load. I need to know if it is possible to save this file into a specific location, separate from appdata, and if I can save separate playerprefs and load them independently. Please let me know if this is possible b/c I would rather not have to rework their code to serialize all the game object s and create game saves that way. Thanks!

Comment
Add comment · Show 3
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 Yinoguns · Aug 18, 2014 at 10:11 PM 0
Share

A bit more specific info would help, ie how it "saves them on exit".

Apart from that with Application.dataPath or persistentDataPath you can get drive locations, and from there perhaps navigate around. You would have to nosey around the $$anonymous$$icrosoft File Documentation for that.

For my Project I had to make a fairly extensive system for detecting, showing and loading all the txt files in a single folder, it can be a challenge.

avatar image Kiwasi · Aug 18, 2014 at 10:24 PM 0
Share

Have you checked out the tutorial on saving and persistent data?

avatar image junctioniv · Aug 19, 2014 at 01:22 AM 0
Share

A bit more specific info would help, ie how it "saves them on exit".

So currently the game saves all variables to playerprefs, and our OnExit() script calls PlayerPrefs.Save(). I know this is not good practice, as it is very slow, and I have suggested changing this. But for the time now I need to create multiple save states using player prefs.

Have you checked out the tutorial on saving and persistent data?

Thanks for pointing this out. I have looked at this before, but I finally sat down to watch the video, and this is the approach I would have used from the beginning as I am familiar with serialization.

As for now I am looking for solutions that can read playerprefs, so I do not have to change the rest of the games's code.

1 Reply

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

Answer by rutter · Aug 18, 2014 at 10:35 PM

The answer to your immediate question is no: there is exactly one PlayerPrefs file, and you cannot control its location.

However, there are other solutions. You could write an abstraction layer. Any script that currently gets or sets values from PlayerPrefs could instead go through some class you write.

Maybe that class adds an extra prefix to each PlayerPrefs key, simulating multiple profiles:

 public static class MultiProfile {
     private static string currentProfile = "default";

     public static int GetInt(string key, int defaultValue) {
         return PlayerPrefs.GetInt(currentProfile + key, defaultValue);
     }
 }


Or, maybe your class serializes its data to some other format, like XML, JSON, or SQL, then reads and writes a file you control directly. Don't forget that you have the full capabilities of the .NET framework -- many powerful serialization libraries exist!

If you're on mobile or web, your options are a bit more limited. Unity iOS doesn't support the use of JIT-compiled code, which knocks out a lot of reflection-based libraries. If you're on web, you don't have direct file access and your PlayerPrefs size limit is much lower.

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 junctioniv · Aug 18, 2014 at 11:12 PM 0
Share

Thanks for the quick response Rutter. This is what I was afraid of. I have not worked with unity before, and I assumed you could not do this since I found no other solutions online.

I will look into a possible abstraction. Thanks for the suggestions.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

UnitySerializer Only Saving one Game Problem 0 Answers

PlayerPrefs HighScore problems, it doesn't work. 4 Answers

C# Issues with either PlayerPrefs.SetVariable or UnityEvent.Invoke 1 Answer

Unable to get save score between levels working 1 Answer


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