LoadInto clarification
Posted: Wed Jan 04, 2023 9:37 pm
I'm trying to save and load game objects with multiple children across multiple scenes using LoadInto. I believe I am correctly saving them, but on load, it does not always replace the game object correctly. Is LoadInto the right way to go about this?
Below is one of my code attempts.
Below is one of my code attempts.
Code: Select all
private void SaveSceneItems(string filePath)
{
// before unloading, save/replace object saved in file with current itemsFolders
GameObject[] loadedFolders = GameObject.FindGameObjectsWithTag("ItemsFolder");
foreach (GameObject folder in loadedFolders)
{
string folderName = folder.scene.name + "ItemsFolder";
ES3.Save(folderName, folder, filePath);
}
}
private void LoadSceneItems(string filePath)
{
// after loading in new scenes, replace current item folders with those in save file
GameObject[] foldersToReplace = GameObject.FindGameObjectsWithTag("ItemsFolder");
foreach (GameObject folder in foldersToReplace)
{
string folderName = folder.scene.name + "ItemsFolder";
if (ES3.KeyExists(folderName, filePath))
ES3.LoadInto<GameObject>(folderName, filePath, folder);
}
}