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 DMCH · Jan 02, 2013 at 07:58 PM · listarraysserializationsavedontdestroyonload

Strategy for saving game

Hello, looking for some advice on a good way to save data between scenes.

What needs to be saved: (Other stuff as well, but most concerned about these):

Booleans (doesn't necessarily need to be in Array)

Weapon Objects (preferably a List or Array, See below)

 using UnityEngine;
 using System.Collections;
 
 public class Weapon
 {
     
     // INSTANCE FIELDS
     private string weaponType;
     private string weaponName;
     private Texture weaponImage;
     private AudioClip weaponSound;
     private float damage;
     private int clipSize;
     private float range;
     private float rateOfFire;
     private int currentClip;
     private float reloadTime;
     private bool isAutomatic;
     
     
     // CONSTRUCTOR
     public Weapon(string weaponTypeIn, string weaponNameIn, Texture weaponImageIn, AudioClip weaponSoundIn, float damageIn, int clipSizeIn, float rangeIn, float rateOfFireIn, float reloadTimeIn, bool isAutomaticIn)
     {
         weaponType = weaponTypeIn;
         weaponName = weaponNameIn;
         weaponImage = weaponImageIn;
         weaponSound = weaponSoundIn;
         damage = damageIn;
         clipSize = clipSizeIn;
         range = rangeIn;
         rateOfFire = rateOfFireIn;
         reloadTime = reloadTimeIn;
         isAutomatic = isAutomaticIn;
         currentClip = clipSize;
     }
 }

Game Structure

2 Primary Scenes : Scene A - > Scene B - > Scene A

The Current Plan

Have a dontdestroy gameobject called tempSave in scene A store all the changes. These changes would affect the game, but wouldn't be permanently stored on the HD. This object would persist until, when in Scene B, the user chooses to return to Scene A. Then all the information would be serialised, and stored on the HD. When Scene A begins, the data would be retreived and a new tempSave object would be created and populated with the info. Does this approach make sense? Are there any problems with it?

Additional Question

I understand there are 2 options for serialising data in unity, one using XML, the other a mono class. Which would be best for my purposes?

Sorry for the long post, and thanks for reading and your help!

Comment
Add comment · Show 2
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 Next Beat Games · Jan 02, 2013 at 10:13 PM 0
Share

use PlayerPrefs ins$$anonymous$$d of DontDestroy. Also, do a search for PlayerPrefsX to save to playerprefs as arrays.

avatar image DMCH · Jan 03, 2013 at 04:13 PM 0
Share

Hello, thanks for the help. Had a quick look at player prefs x. Not sure if it will work, cause I need to store arrays of custom objects. Still trying to get my head around saving, the most I've done in this line so far is writing to text files in java.

1 Reply

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

Answer by jogo13 · Jan 02, 2013 at 10:51 PM

I've used this and it works great: http://pixelplacement.com/2012/03/21/simple-state-saving/

Keep in mind XML is verbose(BLOATED) and saving many variables in serialized XML seems like it could be a bit slow.

I also use this rewrite of player prefs for faster save/load on portable devices: http://www.previewlabs.com/writing-playerprefs-fast/

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 DMCH · Jan 03, 2013 at 04:10 PM 0
Share

Thanks. I was looking at Unity Serializer also. Do you think it makes sense to store all the data needed across scenes in a single dontdestroy gameobject, and load it back into the individual objects when necesary, as opposed to having multiple don't destroyOnLoad object?

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

10 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

Related Questions

A node in a childnode? 1 Answer

Unable to serialize my list in a Unity Custom Editor script. 1 Answer

How do I save and retrieve ordered data? Can I do this with an array? 1 Answer

How to save and load `List myList`? 1 Answer

Private list is serialized inside a prefab 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