Load into a list when list length could change

Discussion and help for Easy Save 3
Post Reply
JordanCW97
Posts: 12
Joined: Thu May 12, 2022 11:00 pm

Load into a list when list length could change

Post by JordanCW97 »

Hi there just a quick general question, I am dealing with an open world game that requires a large number of objects to be saved. Currently I save all the required objects in a list and then use loadinto when loading the game. This works fine however I am concerned about scalability in that if someone has a saved game and then I release an update that potentially alters the list of saved objects whether that be adding new items or removing anything, the user would then not be able to load there game since it would just throw the error that the list we are loading into is of a different size to the target list. Is there a way around this that allows ES3 to recognise the list has changed and simply load everything it can within the list as opposed to throwing an error and loading nothing?

Thanks

Jordan
JordanCW97
Posts: 12
Joined: Thu May 12, 2022 11:00 pm

Re: Load into a list when list length could change

Post by JordanCW97 »

Just to add this is actually also an issue I am having right now not just thinking into the future as I can't keep a consistent save file for testing as I am constantly adjusting the item list meaning it breaks saves almost all the time during development which is making some aspects of testing difficult. I am not sure if this is purely a case of me using the system in an incorrect way or if there is a way around this. Using Load instead of loadinto results in tons of duplicate objects which also is not ideal.

Thanks
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Load into a list when list length could change

Post by Joel »

Hi Jordan, and thanks for getting in contact.

Generally in this circumstance you would use Load instead of LoadInto to load the GameObjects by reference. However, it sounds like new instances of your GameObjects are created at runtime as it's not finding the instances with those instance IDs.

In this case you would need to give each of your GameObjects a unique ID. The easiest way to do this would be by attaching a script such as this to each of your GameObjects:

Code: Select all

using UnityEngine;

public UniqueID : MonoBehaviour
{
	public string id = System.Guid.NewGuid().ToString();
}
Then the simplest way of saving and loading would be to get the GameObject to save and load itself:

Code: Select all

public void Start()
{
	if(ES3.KeyExists(id))
		ES3.LoadInto(id, this);
}

public void OnDestroy()
{
	ES3.Save(id, this);
}
These methods could be added to the UniqueID script, or another script on the GameObject. I've used Start() and OnDestroy() as the events here, but you could simply have these as methods you call yourself, or use whichever events you're using at the moment.

If you take this approach I also strongly recommend using caching as described here, as having a large number of keys in a file significantly impacts performance otherwise: https://docs.moodkie.com/easy-save-3/es ... rformance/

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
JordanCW97
Posts: 12
Joined: Thu May 12, 2022 11:00 pm

Re: Load into a list when list length could change

Post by JordanCW97 »

Hi there, appreciate the response, this is really useful info so will take a proper look this evening thanks!
Post Reply