Optimal Save Method
Posted: Wed Jan 27, 2021 12:37 pm
Hello,
I am looking for guidance on what the optimal way of saving an object is.
My current issue is that I am trying to save a list of prefab instances. I can save this list directly with e.g:
But this leads to a lot of repeated and redundant information in the save file, as it's saving the child objects, their transforms, etc- which are exactly the same for each prefab instance. I'd rather not turn off 'Save Gameobject Children' as I'm relying on this for other objects.
I then changed the code to only save the required components from the object, e.g:
And this works also, with a much smaller save file, but the save time goes way up.
The first method takes 0.17s, and the second takes 3.26s.
Is there a better way to do this, that has the quicker save time, without the repeated save information? Or is my option to turn off 'Save Gameobject Children' and rework the other save objects? But this could lead to the other objects taking up the extra time, as their child objects would need saving seperately.
Thanks,
Elliott
I am looking for guidance on what the optimal way of saving an object is.
My current issue is that I am trying to save a list of prefab instances. I can save this list directly with e.g:
Code: Select all
ES3.Save("citizens", citizenGameobjects;
I then changed the code to only save the required components from the object, e.g:
Code: Select all
int index = 0;
foreach (Citizen citizen in Find.instance.setCitizens.Items)
{
ES3.Save(string.Format("citizen{0}storage", index), citizen.GetComponent<Storage>());
ES3.Save(string.Format("citizen{0}animatorController", index), citizen.GetComponent<AnimatorController>());
ES3.Save(string.Format("citizen{0}citizen", index), citizen);
ES3.Save(string.Format("citizen{0}transform", index), citizen.transform);
index++;
}
ES3.Save("citizenAmount", index);
The first method takes 0.17s, and the second takes 3.26s.
Is there a better way to do this, that has the quicker save time, without the repeated save information? Or is my option to turn off 'Save Gameobject Children' and rework the other save objects? But this could lead to the other objects taking up the extra time, as their child objects would need saving seperately.
Thanks,
Elliott