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 Robomaster · Jun 30, 2012 at 11:30 PM · loadingsavingoption

Saving Levels

Hello again, what im trying to do is create a save and load option, how would i go about doing this so that when they load it all the objects, the economy, and the time within the game is the same as it was when you saved it. Im still learning how to code so please explain it thoroughly. 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
0
Best Answer

Answer by Chimera3D · Jul 01, 2012 at 02:12 AM

Well saving the entire scene isn't going to happen, instead determine exactly everything that you want to save. The easiest way to go about this it to use player prefs. To write the variables to the player preferences file you would use something like this.

 PlayerPrefs.SetInt("Health", playerHealth);

The Health variable is the one being saved to the file and the playerHealth variable is the one in-game. However we are setting the Health thats saved to the playerHealth. Reading these variables is just as easy.

 PlayerPrefs.GetInt("Health");

Will get the health variable from the file for usage. Comparing a player pref in an "if" statement would look like this.

 if(PlayerPrefs.GetInt("Health) >= 100){
          //do something
 }

You can't say...

     if(PlayerPrefs.GetInt("Health, 100){
          //do something
     }

It won't work. Trust me, I had a lot of problems with this a while ago. That's just how to read and write to the files, you can also delete a player pref or delete all of them (like resetting the game). You can also have player pref strings (like the players profile name, ect.) For the rest of the documentation on player prefs: http://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.html

EDIT: I didn't realize you asked another question, sorry.

You can do that by saying:

 PlayerPrefs.SetFloat("LocationX", transform.position.x);
 PlayerPrefs.SetFloat("LocationY", transform.position.y);
 PlayerPrefs.SetFloat("LocationZ", transform.position.z);

Then when loading:

 transform.position.x = PlayerPrefs.GetFloat("LocationX");
 transform.position.y = PlayerPrefs.GetFloat("LocationY");
 transform.position.z = PlayerPrefs.GetFloat("LocationZ");

That's all there is to it!

EDIT (again): Saving each character is theoretically possible, but that may not be necessary. If you really need to save each character then you're going to have to make a separate set of player prefs for each character. :/

Comment
Add comment · Show 8 · 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 Robomaster · Jul 01, 2012 at 02:27 AM 0
Share

Thanks! im making a rts game so how would i save the locations of each character

avatar image Chimera3D · Jul 01, 2012 at 02:28 AM 0
Share

You are supposed to mark an answer as correct when you get a correct answer, just so when someone else has the same question they'll know which was the correct answer.

avatar image Robomaster · Jul 01, 2012 at 02:50 AM 0
Share

Oh forgot sorry!

avatar image Robomaster · Jul 01, 2012 at 03:30 AM 0
Share

ok its marked now how would i go about saving the locations of the characters

avatar image Mizuho · Jul 01, 2012 at 04:27 AM 0
Share

This is totally slow though, so you should only use it if you're not saving that much information. The values saved using PlayerPrefs are flushed EVERY time you set something, which can be very slow if you happen to save that many things.

Show more comments
avatar image
0

Answer by Berenger · Jul 01, 2012 at 12:02 AM

http://lmgtfy.com/?q=unity+save+game

The answers about this are quite thorough, even if mine isn't.

Comment
Add comment · Show 3 · 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 Robomaster · Jul 01, 2012 at 12:31 AM 0
Share

the 3 top searchs ive already looked at, they were alittle difficult to understand since im still new to this, i was hopeing someone could help me out but so that i could also understand it

avatar image whydoidoit · Jul 01, 2012 at 06:53 AM 0
Share

You can certainly use my Unity Serializer to do that, which is the third link the search returned by @berenger's reply. Although it is never easy US makes it as straightforward as possible.

avatar image Robomaster · Jul 01, 2012 at 11:52 AM 0
Share

okay ill take another look at it, thanks

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SerializationException: serializationStream supports seeking, but its length is 0 when trying to load a save game 1 Answer

Newbie questions! (Variables and Saving) 2 Answers

How do you save a player's prefered resolution in Unity 2017.1.1f? 0 Answers

Saving and loading to/from Android 1 Answer

Saving and Loading 0 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