LoadInto clarification

Discussion and help for Easy Save 3
Post Reply
CharlesKleeven
Posts: 5
Joined: Thu Mar 31, 2022 7:11 am

LoadInto clarification

Post 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);
        }
    }
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: LoadInto clarification

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
CharlesKleeven
Posts: 5
Joined: Thu Mar 31, 2022 7:11 am

Re: LoadInto clarification

Post 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.
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: LoadInto clarification

Post 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
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
CharlesKleeven
Posts: 5
Joined: Thu Mar 31, 2022 7:11 am

Re: LoadInto clarification

Post by CharlesKleeven »

Hello,

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