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
3
Question by DGKN · Jul 21, 2014 at 09:38 PM · playerprefssave

Is PlayerPrefs.Save() necessary ? (My game saves without it)

Hi, what does PlayerPrefs.Save() do ? I'm asking this because I just use PlayerPrefs.SetInt() and PlayerPrefs.GetInt() and my game saves perfectly. Why should I use PlayerPrefs.Save() ?

Thanks in advance.

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
6
Best Answer

Answer by dsada · Jul 21, 2014 at 09:44 PM

Im quoting the documentation

"By default Unity writes preferences to disk on Application Quit. In case when the game crashes or otherwise prematuraly exits, you might want to write the PlayerPrefs at sensible 'checkpoints' in your game. This function will write to disk potentially causing a small hiccup, therefore it is not recommended to call during actual gameplay."

In other words it just only for security. Of corse it is not really acceptable if the game crashes but if it does better safe than sorry. So it is recommended to write it to the disk at certain points like pause,scene change, loading etc...

Comment
Add comment · Show 2 · 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 DGKN · Jul 21, 2014 at 09:46 PM 0
Share

Thanks, I'm going to use it then, you never know what could happen :)

avatar image Kiwasi · Jul 21, 2014 at 09:49 PM 1
Share

There are several acceptable reasons for a game to crash that you can do nothing about, and have no warning. An operating system force quit and power failure come to $$anonymous$$d.

These will happen at some point. Its much better if the player looses ten $$anonymous$$utes of progress, rather then three hours.

avatar image
1

Answer by rutter · Jul 21, 2014 at 09:50 PM

PlayerPrefs keeps two copies of its data:

  • One copy is in memory (very fast, but also temporary)

  • One copy is on the hard drive (not as fast, but is permanent)

You can make as many changes as you want, but you'll want to periodically call Save to make sure those changes aren't lost in a crash.

Some people call Save after every change. That's fine, if you don't have a lot of data.

Other people call Save each time they switch scenes, or at some other sort of reasonable checkpoint.

The docs are saying Save should be called automatically when your application exits. That's new to me, and I'm guessing it was added recently. Possibly in Unity 4.3

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 DGKN · Jul 21, 2014 at 10:01 PM 0
Share

Thanks for the information ! I'm going to use it after every change as my game just saves an integer on Game Over, so I guess it's okay.

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

25 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

Related Questions

PlayerPrefs and own Class 1 Answer

Save decimals in PlayerPrefs c# 2 Answers

Save values on different objets with same script? 1 Answer

How can I continue the game without losing values after Game Over? 1 Answer

Saving and loading game with PlayerPrefs 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