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 Blackice000 · Nov 15, 2011 at 12:30 AM · saveloadxml

Save and Load plus a few other stuff

I am having a little trouble with some stuff at Unity. First of all, what is the best way to save and load a PC Plataform game?

If it's XML, can someone show me a good and simple example? Because the one I made I got nullreferences at them. If needed, I'll post the code down.

Next issue: When loaded, how to set those values to the right places? Put them through the Start from the codes? Isn't there an easier way? Like a Data Bind, or something?

I am getting null in these:

  `currentHealth = InfoHolder.Instance.CurrentHP;`

And on the SaveData below, that is the InfoHolder.

 > using UnityEngine; using
 > System.Collections;
 > 
 > public class InfoHolder :
 > MonoBehaviour {
 >     public static InfoHolder Instance;
 > 
 >     //Preencher com os mesmos valores que
 > vão ser usados no SaveData. Quando o
 > jogo for carregado, serão passados
 > para cá os valores e vice-versa quando
 > salvo.
 >     //Procure e preencha daqui os valores.
 > 
 >     public int CurrentHP = 100;
 >     public int MaxHP = 100;
 >     public int CurrentMP = 100;
 >     public int MaxMP = 100;
 >     public int Fruits = 0;
 >     public bool LevelChocLabEnter = false;
 > 
 >     public void Bezier()
 >     {
 >         switch (Application.loadedLevel)
 >         {
 >             case 1:
 >                 LevelChocLabEnter = true;
 >                 break;
 >         }
 >     }
 > 
 >     public void CallSave()
 >     {
 >         SaveData.Instance.CurrentHP = CurrentHP;
 >         SaveData.Instance.MaxHP = MaxHP;
 >         SaveData.Instance.CurrentMP = CurrentMP;
 >         SaveData.Instance.MaxMP = MaxMP;
 >         SaveData.Instance.Fruits = Fruits;
 >         SaveData.Instance.levelReached = Application.loadedLevel; //Essa variável pega o último level em que o
 > personagem pisou.
 >         SaveData.Instance.LevelChocLabEnter =
 > LevelChocLabEnter;
 > 
 >         SaveLoad.Save();
 >     } }


Thanks in advance, Pedro Loures.

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 DaveA · Nov 15, 2011 at 12:31 AM 0
Share

You should split these into separate questions so they get answered faster. You can google for saving and loading game data in Unity (spoiler: it's up to you)

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Caiuse · Nov 15, 2011 at 11:37 AM

Great community made XML parser :

http://www.unifycommunity.com/wiki/index.php?title=Save_and_Load_from_XML

a good class structure for the data is the best way of storing the data in the XML

Hope this helps - C

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 Blackice000 · Nov 15, 2011 at 12:38 PM

I've seen that, and that did help, what I wanted was to understand where can I set what else do I want to save. Since that seems to save only the player position, and I wanna save lots of variables.

And for some reason, I dunno why, the InfoHolder.Instance.Bezier(), for example, is returning as null, as I can't do it like that, even though I did it just like it before with my Third Person Control.

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 Caiuse · Nov 15, 2011 at 12:48 PM 0
Share

Only classes that can be serialised can be "saved"

I would suggest storing all your information in a class then serialising that class.

http://msdn.microsoft.com/en-us/library/system.xml.serialization.aspx

avatar image
0

Answer by Blackice000 · Nov 15, 2011 at 02:22 PM

I know how to use the serialization, but ok, I made it work. I couldn't use instance because they weren't in the same object. I then had to made the methods public and static. With that I could acess them. Saving and Loading was easier to understand once that worked out.

Thanks for the help, Caius1!

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Xml Saving and Loading Problems 1 Answer

Save/Load game using XML on Browser/Web Player 2 Answers

Saving Game Problem 1 Answer

Editing an XML File 1 Answer

Save/Load system is saving but not loading. 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