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
1
Question by Caiuse · Jun 17, 2011 at 11:52 AM · playerprefsstringkeys

Create a list of all PlayPref Keys

Hi there, basically we've created a character creator system that used PlayerPref keys to store the character configuration. I want to create a character select screen but using all the string names of each of the saved characters names. Is there a way I can create a array from all the PlayerPref keys?

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

Answer by Anxo · Jun 17, 2011 at 12:09 PM

  • good question.

I would also like the answer to this. This would be my first approach but seams like a headache.

Instead of storing it by name, I would store them by number, and every piece of equipment also. So Hat might be stored in 1, boots in 2 and so on. Then the type of boots would also be a number like black is 1 and blue is 2. Lost yet? Then the first stored character could look like this:

PlayerPrefs.SetString("1","0202");

Then you could write an algorithm that decodes that the first 2 indexes in the string tell you what kind of hat he/she has on and the second 2 indexses tell you what kind of boots he/she has on. Blue Blue. That would allow you to store lots of characters and their setups without storing thousands of variables.

And Storing it by number would allow you to sweep through it using a for loop.

 function CheckForCharacter(){
 for(var i=0; i<1000; i++)
 {
 if(PlayerPrefs.HasKey(i))
 {
 do something
 }
 else
 {
 return;
 }
 } 
 }

What do you think?

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 Caiuse · Jun 17, 2011 at 06:45 PM 0
Share

Almost the way in which we've already set it up, but I'v given each a string variable name so I can call in using a "player name" I think the array solution Is probably the way to go, but thanks!

avatar image
1

Answer by Twayne · Jun 17, 2011 at 12:23 PM

I use ArrayPrefs. You can load the prefs as an array and save the prefs as an array directly.

Comment
Add comment · Show 7 · 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 Bunny83 · Jun 17, 2011 at 01:00 PM 0
Share

It's the best workaround at the moment ;)

Just to have it said: It's not possible to get a list of all stored PlayerPrefs (yet).

avatar image Anxo · Jun 17, 2011 at 03:49 PM 0
Share

ArrayPrefs are great, the only problem is that if you are creating a mobile game, ArrayPrefs is very heavy.

avatar image Caiuse · Jun 17, 2011 at 06:43 PM 0
Share

I like the sound of this, I will try it and get back to you, Although apart form using the PlayerPref functions what would be a less CPU heavy alternative to storing character creation data?

avatar image Twayne · Jun 17, 2011 at 07:35 PM 0
Share

I believe this is less heavy than separate string playerprefs. The array ends up being stored as a single string pref with separators. The CPU cost is small because, i think, you would only save when the user clicks DONE or APPLY. Then unity builds the string from the array of strings and saves it to prefs.

avatar image Caiuse · Jun 20, 2011 at 08:52 AM 0
Share

Okay here comes the question:

 string[] names = PlayerPrefsX.GetStringArray("Names");
 for (int i = 0; i < names.Length; i++)
     names[i] = prefName+(i+1);
 if (!PlayerPrefsX.SetStringArray("Names", names))
     print("Can't save names");

How do I add a prefName to an existing string of PrefNames?

Show more comments

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Store individual positions of GameObjects in a string 3 Answers

Using Player Prefs 0 Answers

If Statements with PlayerPrefs 1 Answer

Display PlayerPrefs.GetInt? 1 Answer

How to get Steam Username? 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