Hi Joel,
What do I need to be able to use multiple threads to load a large amount of objects with Easy Save 3?
I have an idea that using 5 threads to instantiate 5000 objects, each thread will initialize 1000 objects is this possible and how can I do that?
For now I use this code to save and load game from Easy save 2
How can I use thread solution with this save and load code ?
// To Save.
using(var writer = ES2Writer.Create("myFile.txt"))
{
writer.Write(CreatedObjects.Count);
foreach(var uniqueID in CreatedObjects)
{
writer.Write(uniqueID.id);
writer.Write(uniqueID.prefabName);
writer.Write(uniqueID.transform);
}
writer.Save(false);
}
// To Load.
using(var reader = ES2Reader.Create("myFile.txt"))
{
int count = reader.Read<int>();
// Optional: You may want to destroy each object in the createdObjects list and clear the list here
// to prevent duplicates. I haven't done so in this example however.
for(int i=0; i<count; i++)
{
int id = reader.Read<int>();
string prefabName = reader.Read<string>();
// Get your prefab and instantiate it.
var prefabInstance = UniquePrefabManager.InstantiatePrefab(prefabName);
// Read the Transform into the prefab instance's Transform using self-assigning load.
reader.Read<Transform>(prefabInstance.transform);
}
}
It's great that it's possible to have more cached files for loading at the same time. I have game save file opened and meantime some other stuff is being loaded from different files.
But I've been wondering if I should do some cleaning once loading from cached file is done? Before, when using traditional loading from File, I've just set file to null at the end.