Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
This question was closed Mar 05, 2020 at 09:11 AM by cupcake007 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by cupcake007 · Mar 04, 2020 at 03:50 AM · save datasaveloadloading file

Saving current progression question

Ok, so I have two string arrays that I want to save and load on game start. All current daily quests are saved into one array (itemsList[]). All completed daily quests are saved in the other array (completedItemsList[]).

I have a Serialzation/Deserialization script for saving and loading the data.
At runtime, the current daily quests (itemsList[]) are loaded just fine. My problem is saving and loading the completed daily quests (completedItemsList[]).
When I click on a game object corresponding to a current daily quest, I want the name of that quest to be added to the completedItemList[] and then save the state. The completed daily quests do not save though.
This is my save/load Serialization/Deserialization code that saved the data to a file in binary.

 using UnityEngine;
 using System.IO;
 using System.Runtime.Serialization.Formatters.Binary;
 
 public static class SaveSystem
 {
     public static void SavePlayer(Player player)
     {
         BinaryFormatter formatter = new BinaryFormatter();
         string path = Application.persistentDataPath + "/1.yummy";
         FileStream stream = new FileStream(path, FileMode.Create);
         playData data = new playData(player);
 
         formatter.Serialize(stream, data);
         stream.Close();
     } 

     public static playData LoadPlayer()
     {
         string path = Application.persistentDataPath + "/1.yummy";
         if (File.Exists(path))
         {
             BinaryFormatter formatter = new BinaryFormatter();
             FileStream stream = new FileStream(path, FileMode.Open);
 
             playData data = formatter.Deserialize(stream) as playData;
             stream.Close();
 
             return data;
         }
         else
         {
             Debug.LogError("Save not found in " + path);
             return null;
         }
     }
 }


This is my data that I want to save and load:

 using System.Collections;
 using System.Collections.Generic;
 using System.Linq;
 using UnityEngine;
 
 [System.Serializable]
 public class playData
 {
     public string[] allItems = new string[Player.itemsList.Count];
     public string[] completedItems = new string[Player.completedItemsList.Count];
     public int containCounter;
     
     public playData (Player player)
     {
         int count = 0;
         foreach(string a in Player.itemsList)
         {
             allItems[count] = a;
             
             count++;
 
         }
         int cc = 0;
         foreach(string c in Player.completedItemsList)
         {
             if(completedItems[count] != null)
             completedItems[count] = c;
             
             cc++;
             
         }
     }
 }

This is where the actual data is saved/loaded:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Player : MonoBehaviour
 {
     public static List<string> itemsList = new List<string>();
     public static List<string> completedItemsList = new List<string>();
     public static int containCountHolder;
 
 
     public void Start()
     {
         
         playData data = SaveSystem.LoadPlayer();
         
         for (int count = 0; count < 100; count++)
         {
 
             itemsList.Add(data.allItems[count]);
             completedItemsList.Add(data.completedItems[count]);
 
         }
         
     }
     public void Update()
     {
         SaveSystem.SavePlayer(this);
     }
 }


I have an OnClick event for each game object corresponding to each current daily quest string. This onClick event should take the EventSystem.current.currentSelectedGameObject.name, and save that in the completedItemsList[].
When I start game trying to load compeletedItemsList[],, I get an error message like this: alt text

When I load the game WITHOUT the completedItemsList, everything works pretty well.

97cecaa26efaf82cd1aef91524d75206.png (80.9 kB)
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

0 Replies

  • Sort: 

Follow this Question

Answers Answers and Comments

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

Related Questions

Saveing and Loading Problem 0 Answers

How do i Make this saving system apply the save data in my game. 0 Answers

[Error:] Cannot Deserialize JSON to new instances of type ' X ' 1 Answer

how do i keep object destroyed after reloding scene ?? 0 Answers

Save location of created UI elements to JSON so it can load later 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