Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 Lainex · Aug 14, 2015 at 07:08 AM · destroylivesprefs

PlayerPref or DontDestroyOnLoad for lives

So I'm creating a live system for my game, where when the player dies, the level gets reloaded with Aplication.LoadLevel(), but the amount of lives should stay, so I'm wondering which way of doing this is better practise or is better performance wise? Using a singleton(so it doesn't get duplicates) gameObject containing information about the amount of lives, wich I don't destroy using DontDestroyOnLoad or using PlayerPref to set lives or is there another way of doing this?

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

3 Replies

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

Answer by stepan-stulov · Aug 14, 2015 at 07:44 AM

  1. PlayerPrefs is a persistent storage of data. What that means is the values saved there are saved between game restarts. This is a fairly traditional and easy to use place to put your savegames.

  2. DontDestroyOnLoad is (or more correctly: can be used as) runtime storage of data. DontDestroyOnLoad is supposedly a method that tells a game object to not be destroyed on entering another scene. But as far as I know it doesn't do exactly what the name suggests. I think it actually recreates the same object. Which may lead to duplications of game objects and other artefact. From my experience I would avoid DontDestroyOnLoad at all cost. It's a half measure and a very weird hacky method in general.

What should you use? Do you want player lives to persist between game launches? If so — PlayerPrefs or any other available serialization tool (like Thrift for example, or even standard .NET serialization and file I/O). If not — something runtime-only, but also not DontDestroyOnLoad as my humble recommendation.

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
avatar image
1

Answer by StaNov · Aug 14, 2015 at 07:49 AM

From what you are saying it seems that level-reload happens very rarely (like twice a minute for example I guess), so solving performance issues seems unnecessary. Stick with the first rule of optimization.

Putting lives-counter into DontDestroyOnLoad object seems conceptually better. If you have a lot of preferences, you may want to have only preferences in PlayerPref. But if you have only little preferences, it doesn't matter where you put the lives-counter.

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
avatar image
0

Answer by Lainex · Aug 14, 2015 at 10:09 AM

Alright, thanks everyone! I decided to go with PlayerPref, because it does seem more practical and less messy, even though I feel kinda dirty for saving stuff on others computers.

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

Pick up objects 2 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Is this a good practice for mobile devices? 2 Answers

Destroy fireball on impact 0 Answers

Destroy character controller and instantiate new one 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