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
0
Question by Klarax · Oct 03, 2014 at 09:44 AM · serializationloadingsavingserialize

Saving Game Confussion

Hello,

I have been using Unity for 1 year and as of now, have yet to try and save a game.

I have a few questions, that I'm not to sure about relating to saving that I was hoping you could answer.

1) does any class that have is serializable automatically get saved? or is this line just telling unity that it can be saved, and then has be to saved manually by another script. (hope that makes sense)

2) do i need to get reference to each script to save it, or can I get the GameObject to save (and the script gets saved automatically because its set to serializable.

3) does each script that is serializable need a save function to be called?

4) how does the main save function work - i.e. does it call every script that is serializable as mentioned in point 3. or is it a much smaller function, and unity sorts out everything in the background (kinda).

Well i hope all that makes sense. Its hard to talk about things when you not sure how things work to begin with...

Any answers are welcome, since at this moment in time, my head hurts from reading :P

Thanks

Klarax

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 Benproductions1 · Oct 03, 2014 at 10:43 AM 0
Share

You might want to look up what serialization actually is, because (like most things) if something is given a same, it actually does what the name implies.

Also note that Unity doesn't have a "save" functionality built in.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Superrodan · Oct 03, 2014 at 10:54 AM

The easiest way to save things, I've found, is saving to PlayerPrefs. To save an integer to PlayerPrefs, for example, you would use this line of code:

 PlayerPrefs.SetInt("Player Score", 10);

This would save a value of 10 to PlayerPrefs under the name "Player Score" for you to collect later. You can save ints, floats, bools, and other things.

Additionally, by using a script found here:

http://wiki.unity3d.com/index.php/ArrayPrefs2

you can save arrays to player prefs. So if you can store variables into an array and create a load function that goes through the array and uses the variables to restore your game, that would be one way to save a game. Remembering all the things you need to save and creating a script that loads those things and restores a game can be daunting, but it's the easiest way to do it that I've found.

For a bit more information about PlayerPrefs, check here: http://docs.unity3d.com/ScriptReference/PlayerPrefs.html

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 Superrodan · Oct 03, 2014 at 10:56 AM 0
Share

I'd like to point out that I'm a Unity beginner so if someone who knows better comes along I'd be happy to be corrected.

avatar image Benproductions1 · Oct 03, 2014 at 10:44 PM 0
Share

PlayerPrefs (as the name suggests) should be used to save preferences. This is especially the case on windows, where it saves to the windows registry (basically a giant mess of a database for preferences). This also makes it a lot more difficult to debug.

This question has some better suggestions.

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

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

Related Questions

Newbie questions! (Variables and Saving) 2 Answers

Serializing a graph 2 Answers

Serializer Script 3 Answers

how to properly save an int value ? 2 Answers

I am getting a serialization exception error when trying to save and load in Unity? 2 Answers


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