I am attaching saved file where you can in see in Sprite Renderer that
Code: Select all
"sprite" : {
"_ES3Ref" : "6429260329939571930"
},
Code: Select all
public void SaveColonists(string saveName)
{
List<GameObject> saveGOs = new();
foreach (Colonist c in _colonists) //_colonists is monobehaviour script
{
saveGOs.Add(c.gameObject);
}
ES3.Save(SAVE_COUNT, saveGOs.Count, saveName);
ES3.Save(SAVE_LIST, saveGOs, saveName);
}
Code: Select all
public void LoadColonists(string saveName)
{
List<GameObject> loadGOs = new();
int itemsCount = ES3.Load<int>(SAVE_COUNT, saveName);
for (int i = 0; i < itemsCount; i++)
{
loadGOs.Add(SpawnColonist(new Vector2Int(0, 0)).gameObject); //SpawnColonist instantiate prefab with colonist script, sprite renderer
}
ES3.LoadInto(SAVE_LIST, saveName, loadGOs); //game objects are loaded to prepared instances - you use this approach in one of the tutorials and it fits to what I want to achieve
foreach (GameObject go in loadGOs)
{
_colonists.Add(go.GetComponent<Colonist>());
}
}
Thank you!