Search Unity

Saving Objects

Discussion in 'Scripting' started by Cooper37, Jan 13, 2015.

  1. Cooper37

    Cooper37

    Joined:
    Jul 21, 2012
    Posts:
    383
    Hi Unity Community! I know saving is a tough topic in the Unity3D world and yet there's a lot of resources that expounds on this topic, but I many need some ideas on how to save gameObjects and the information they carry. See, I have a custom mission editor that works with empty gameObjects and their unique scripts. Isn't there a way for me to save specific information like, saving if a gameObject's script has already executed, saving if a gameObject has been SetActive, saving lights or skyboxes, saving objects(if they are already destroyed or not).

    Basically, I'm trying to figure out that each time a gameObject has been SetActive or the script has already been executed, the player would be able to cut the game off and then resume right where they were with gameObjects SetActive or not, and scripts already executed or not, along with the gameObjects they may control.

    Which would be best for what I'm trying to do? PlayerPrefs, XML, Singleton? I'm not too familiar with the last two, so any good references would be great. Thank you! :)
     
  2. shotoutgames

    shotoutgames

    Joined:
    Dec 29, 2013
    Posts:
    290
  3. Cooper37

    Cooper37

    Joined:
    Jul 21, 2012
    Posts:
    383
    Ok, I'm following the tutorial and I think I can make it work, it's just that I prefer Java than C#. I can translate most of the code to Java except line 5:
    Code (csharp):
    1.  
    2. public function Load(){
    3.     if(File.Exist(Application.persistentDataPath + "/PlayerData.dat")){
    4.         var bf = new BinaryFormatter();
    5.         playerFile = File.Open(Application.persistentDataPath + "PlayerData.dat");
    6.         playerdata = (PlayerData)bf.Deserialize(playerFile);
    7.         playerFile.Close();
    8.     }
    9. }
    10.  
    Can anyone help me translate line 5 to Java Script?
     
  4. Deleted User

    Deleted User

    Guest

    I had issues converting this as well,
    anyway here it is:


    Code (JavaScript):
    1. static public function Load() {
    2.     if (File.Exists (Application.persistentDataPath + "/PlayerData.dat"))
    3.     {
    4.         var bf: BinaryFormatter = new BinaryFormatter();
    5.         var file: FileStream = File.Open(Application.persistentDataPath + "/PlayerData.dat", FileMode.Open);
    6.         var data: PlayerData = bf.Deserialize(file);
    7.         file.Close();
    8.     }
    Hope it helps,
    - Lulz