Page 1 of 1

LoadInto clarification

Posted: Wed Jan 04, 2023 9:37 pm
by CharlesKleeven
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.

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);
        }
    }

Re: LoadInto clarification

Posted: Thu Jan 05, 2023 9:59 am
by Joel
Hi there,

Could you explain a bit more about how it's not replacing the GameObject correctly?

Also be aware that order isn't guaranteed when calling FIndGameObjectsWithTag, so the order of GameObjects in the list will often change.

All the best,
Joel

Re: LoadInto clarification

Posted: Thu Jan 05, 2023 10:30 am
by CharlesKleeven
Hello,

Some children objects keep being instantiated on load even when the parent object has been saved with them removed. I've tried adding all the scripts to the ES3 Types, but the problem persists. Some objects are being loaded in correctly (positions correctly updated and no duplicates), while others have duplicated objects both in the new saved positions and in the old positions.

Re: LoadInto clarification

Posted: Thu Jan 05, 2023 11:46 am
by Joel
Hi there,

Please could you replicate your issue in a new project work a simple scene and private message it to me with instructions so I can see what is happening.

All the best,
Joel

Re: LoadInto clarification

Posted: Thu Jan 05, 2023 1:19 pm
by CharlesKleeven
Hello,

I've created a new project and sent it over to you with instructions. Thanks for the help.