- Home /
My Load function isn't working and now I'm getting an error..
I have a Save Manager set up to save 3 different stats on two characters. 2 sets of in hand objects, 2 sets of inventory's and a chest management.
The chest management and the in hand objects seem to save and load fine, however the inventory doesn't. Originally my chest wasn't saving properly and I was getting the following error "InvalidOperationException: Collection was modified; enumeration operation may not execute." after a brief search this lead me to add .ToArray() to line 85 of my code. This fixed the chest however the inventory still didn't want to play ball.
I was then receiving no error of any kind and had tried rebooting etc. I then decided to remove the script from the game object and reattach it and am now getting the following error "NullReferenceException: Object reference not set to an instance of an object SaveManager+c__Iterator0.MoveNext () (at Assets/Scripts/SaveManager.cs:57) UnityEngine.MonoBehaviour:StartCoroutine(String) SaveManager:Awake() (at Assets/Scripts/SaveManager.cs:24)"
The lines mentioned in the errors are below along with a link to the entire script.
Original error:
foreach(SerializableCheset sc in chests.ToArray())
{
while (!GameManager.Instance.FindChestWithID (sc.ID).HasGenerated)
{
yield return new WaitForEndOfFrame();
}
GameManager.Instance.FindChestWithID(sc.ID).LoadItems (sc._MyItemsString);
}
New error, lines 21- 25:
void Awake()
{
Instance = this;
StartCoroutine("Load");
}
New error lines 52-57:
public IEnumerator Load()
{
byte[] b = File.ReadAllBytes (Application.persistentDataPath + path);
List<object> o = DeSerialize (b);
p1_Hand = GameManager.Instance.FindItem ((string)o[0]);
for the entire script please use this link Script
Thank you for any assistance you might be able to give.
It looks like the list "o" is null or empty, can you set a breakpoint after the "DeSerialize" line and check what's the state of that list?
Your answer
Follow this Question
Related Questions
Save the inventory items to the database 0 Answers
Cannot load a saved game 1 Answer
Save and load an inventory 0 Answers
Saving/Load using menu C# 1 Answer
Loading a list into unity 0 Answers