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
1
Question by youngapprentice · Aug 13, 2012 at 06:23 PM · arrayfunctionplayerprefssaving

ArrayPrefs 2 (PlayerPrefs X) Question

Is there a way I could do a HasKey function using PlayerPrefsX? The reason I ask this is because when there is no value stored in a key for an array, it returns an empty array. This is alright, but I have some 2D and 3D arrays I need to use and when the game hasn't been saved, it returns them as 1D arrays. If there was a HasKey function I would be able to prevent this... Any ideas?

Thanks!- YA

Comment
Add comment · Show 1
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 youngapprentice · Aug 14, 2012 at 01:01 AM 0
Share

Also, is there a possible workaround? Thanks!

2 Replies

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

Answer by Screenhog · Aug 14, 2012 at 06:14 PM

Simply use PlayerPrefs.HasKey.

PlayerPrefsX converts other types into a type that PlayerPrefs can understand. When you're saving data with PlayerPrefsX, it's converting to PlayerPrefs behind the scenes. Thus, PlayerPrefs.HasKey just works.

Comment
Add comment · Show 12 · 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 youngapprentice · Aug 14, 2012 at 06:22 PM 0
Share

And yet, I still get the error thrown at me. I need a way to either make an exception and block the error, or how to Save/Load 2D arrays in PlayerPrefsX.

Is this possible?

avatar image Screenhog · Aug 14, 2012 at 06:37 PM 0
Share

When saving a 2D array, could you save it as a 1D array, and save another array of ints, with each int being the length of the line in the 2D array? When loading the array as a 1D array, use your array of ints to break it up into the pieces you need.

For a 3D array... I don't know.

avatar image youngapprentice · Aug 14, 2012 at 06:45 PM 0
Share

Interesting... Well I could just as easily use the same strategy for the 3D. Last question, and you've been great thank you very much:

Can I save a variable directly as opposed to referencing a key in an array?

I would like to go

PlayerPresX.SetInt((PlayerPrefsX.GetIntArray("$$anonymous$$yArray")[2]),3);

That would find the index of the Array I loaded and save that variable. Sadly I get errors thrown at me when I try this as well. Is there another way?

Thanks- YA

avatar image Screenhog · Aug 14, 2012 at 07:03 PM 0
Share

No, that's not possible, and it's not really what PlayerPrefs are designed for. The only goal of PlayerPrefs is to be able to save and load from your computer's memory. The better practice would be to load your array once and save your array to an in-game variable, and then get your information from that.

avatar image youngapprentice · Aug 14, 2012 at 07:19 PM 0
Share

I understand that. The above code is actually then saved into a variable.

$$anonymous$$y goal here is simply this: I have one set of variables. For instance: Name, $$anonymous$$oney, and, say, Level.

In my game there are 3 save slots. So I would have 3 arrays with 3 values each, representing the value assigned to each slot. So ins$$anonymous$$d of going

If Slot number == 1{ Name = Slot1Name } if SlotNumber == 2{ Name = Slot2Name } if SlotNumber == 3{ Name = slot3Name }

Ins$$anonymous$$d I can go:

Name = Names[Slot];

And yes that was all psuedo-code ;)

But what if I need to make 3 different arrays for each save slot? Then what do I do? This problem is perplexing for me and I cannot find a good solution to it. :/

Show more comments
avatar image
0

Answer by DavidBrehl · Dec 24, 2017 at 08:37 PM

how the hell do i get arrayprefs 2!??!?!!??

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 Fragmental · Apr 03, 2018 at 06:22 AM 0
Share

first result if you google "arrayprefs 2" http://wiki.unity3d.com/index.php/ArrayPrefs2

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

10 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

Related Questions

How do you save GameObject[]? 1 Answer

How to create a save and load game proccess like SCP: Containment Breach? 0 Answers

Save Values On Closing of Game 1 Answer

Create GUI based on an array 2 Answers

Saving Location in Unity 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