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
0
Question by Akashic · Sep 08, 2011 at 07:57 AM · 2dplayerprefsmultidimensional

Multidimensional PlayerPrefs

Is there a method for saving Multidimensional arrays as PlayerPrefs? (PlayerPrefsX only gives the option to save 1-dimensional array)

For that matter, any option for transfering multidemsional arrays between scenes would be nice (doesn't neceseraly need to be PlayerPrefs)

Any help would be greatly appreciated.

Comment
Add comment · Show 2
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 SilverTabby · Sep 08, 2011 at 09:30 AM 0
Share

On PlayerPrefs, no there should not be a way to have 2-d arrays for one big reason: memory usage. On the webplayer, you only get to save ~1$$anonymous$$B of data into PlayerPrefs. A pure 2-d array of ints with absolutely no wasted room (pointers, $$anonymous$$eys, ways to actually find the data inside it, etc.) could only hold a 256X256 array. Useful for small applications, but not for anything major.

If you really want store large amounts of data between scenes, store the data in a GameObject, and somewhere in that GameObject, call

 DontDestroyOnLoad(this.gameObject);

DontDestroyOnLoad will preserve the GameObject and all data inside of it across levels. Just be careful you don't end up with two of them if you reload the original level.

avatar image eAi · Sep 19, 2011 at 09:27 AM 0
Share

I don't know why you'd assume 2D arrays are going to be any larger than 1D arrays. They surely could be, but if you wanted to store a noughts and crosses game (for example), they'd only need to be 3 3 2 bytes.

Using DontDestroyOnLoad is far better though, if you don't need persistence between sessions.

1 Reply

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

Answer by syclamoth · Sep 19, 2011 at 10:57 AM

As per the comments above, you should only be using PlayerPrefs for saving basic configuration info etc. between sessions- if you have large data structures that you only need to keep between scenes, calling DontDestroyOnLoad on the gameObject to which those scripts are connected is a much cleaner way of stopping things from getting deleted.

If you want to save larger quantities of data, you should look into C#'s inbuilt XML serialization libraries- you can save detailed game information into an xml file in a known location and load from that.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Multidimensional PlayerPrefs? 1 Answer

Help with Load function on Button press 1 Answer

Multidimensional array trouble 2 Answers

2D Animation does not start 1 Answer

Want to make a JRPG. 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