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
Load into a list when list length could change
-
- Posts: 12
- Joined: Thu May 12, 2022 11:00 pm
-
- Posts: 12
- Joined: Thu May 12, 2022 11:00 pm
Re: Load into a list when list length could change
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
Thanks
Re: Load into a list when list length could change
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:
Then the simplest way of saving and loading would be to get the GameObject to save and load itself:
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
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();
}
Code: Select all
public void Start()
{
if(ES3.KeyExists(id))
ES3.LoadInto(id, this);
}
public void OnDestroy()
{
ES3.Save(id, this);
}
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
-
- Posts: 12
- Joined: Thu May 12, 2022 11:00 pm
Re: Load into a list when list length could change
Hi there, appreciate the response, this is really useful info so will take a proper look this evening thanks!