Page 2 of 3

Re: Persist Scriptable Objects between scenes

Posted: Fri Sep 25, 2020 6:46 am
by JoseHawk
Hello,

These objects are not created during runtime, these are part of the scene.

I believe that aaaaaaaall my problems are related to something that I am missing about updating references or whatever, because some things that were not working, now are magically working. Should I press some button or run whatever command?

I have a clear example about this issue. I was testing the saving of the "collectables", that were not saving properly. After many tries, now this is working, so I decided to replicate the same code with the "triggers". This is the related code:

Code: Select all

 public class SaveManager : MonoBehaviour
    {
        [SerializeField] private List<Collectable> collectablesToSave;
        [SerializeField] private List<Trigger> triggersToSave;
        [SerializeField] private List<Room> roomsToSave;

        private static SaveManager sharedInstance;
        
        private void Awake()
        {
            sharedInstance = this;
            UnityEngine.SceneManagement.SceneManager.sceneLoaded += OnSceneLoaded;
        }

        public static SaveManager GetSharedInstance()
        {
            return sharedInstance;
        }

        public void SaveGame(Player player, int sceneIndex)
        {
            ES3.Save("player", player);
            ES3.Save("inventory", player.Inventory);
            ES3.Save("scene_index", sceneIndex);
            ES3.Save("collectables_" + SceneService.GetCurrentSceneIndex(), collectablesToSave);
            ES3.Save("triggers_" + SceneService.GetCurrentSceneIndex(), triggersToSave);
            ES3.Save("rooms_" + SceneService.GetCurrentSceneIndex(), roomsToSave);
        }
        
        private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
        {
            var player = SearchService.SearchGameObjectByTag(TagName.PLAYER);
            
            if (ES3.KeyExists("player") && player != null)
            {
                ES3.LoadInto("player", player.GetComponent<Player>());
                player.transform.position = player.GetComponent<Player>().CheckPoint;
            }
            
            if (ES3.KeyExists("inventory") && player != null && player.GetComponentInChildren<Inventory>() != null)
            {
                ES3.LoadInto("inventory", player.GetComponentInChildren<Inventory>());
            }

            if (ES3.KeyExists("collectables_" + scene.buildIndex))
            {
                ES3.LoadInto("collectables_" + scene.buildIndex, collectablesToSave);
            }
            
            if (ES3.KeyExists("triggers_" + scene.buildIndex))
            {
                ES3.LoadInto("triggers_" + scene.buildIndex, triggersToSave);
            }
            
            if (ES3.KeyExists("rooms_" + scene.buildIndex))
            {
                ES3.LoadInto("rooms_" + scene.buildIndex, roomsToSave);
            }
        }
}
As you can see, whit the save method I create this new key with the different elements. The code is exactly the same for "collectables" than "triggers", but collectables are working and triggers not.

The same was happening before with the inventory, that was not working and now is magically working.

I am sure that I am missing something that will solve all these issues.

Thank you in advance.

Re: Persist Scriptable Objects between scenes

Posted: Fri Sep 25, 2020 6:50 am
by Joel
Hi there,

References should be automatically updated, unless you've changed the settings in the Easy Save 3 Settings panel. If you're able to send me a new project which replicates this I'll be happy to look into it further :)

All the best,
Joel

Re: Persist Scriptable Objects between scenes

Posted: Fri Sep 25, 2020 7:03 am
by JoseHawk
I was debugging and saw that I am getting errors when saving the "triggers". I don't know why, as I just replicated exactly the same than with the "collectables". All of them are prefabs and all of them are in the scene (nothing is created during runtime). I am just becoming crazy :roll:

Re: Persist Scriptable Objects between scenes

Posted: Fri Sep 25, 2020 7:06 am
by Joel
Hi there,

Unfortunately I won't be able to debug this without seeing a basic project which replicates this.

All the best,
Joel

Re: Persist Scriptable Objects between scenes

Posted: Fri Sep 25, 2020 7:06 am
by JoseHawk
Here are more screens about the settings of the Easy Save.

Sorry for not sending you a small project, but it would take me really long time to develop as my solution is a bit complex... If I am not able to find the issue, I will do that, but I would like to try first to identify the problems.

Re: Persist Scriptable Objects between scenes

Posted: Fri Sep 25, 2020 8:37 am
by JoseHawk
Hello Joel,

I am sorry for being so annoying, but I believe it is should be something really simple that I am missing. I was touching everywhere (removing the Easy Save manager and so on) and now the "collectables" are not working any longer and the code has not change at all.
  • I double-click in the prefab and selected "add Refence(s) to Manager".
    I also tried with the refresh.
    In the Editor Settings I have slected the "Auto Update References", "Use Global References", "All All prefabs to Manager".
Thanks.

Cheers.

Re: Persist Scriptable Objects between scenes

Posted: Fri Sep 25, 2020 10:35 am
by Joel
Hi there,

As we've had no other reports of this and I've not been able to replicate it at my end, I'd appreciate it if you could send a test project for me to try. Otherwise it's not possible for me to tell what is happening.

All the best,
Joel

Re: Persist Scriptable Objects between scenes

Posted: Sat Sep 26, 2020 10:13 am
by JoseHawk
Hello,

I finally found the issue. As I though, it was something related to configuration. In this case, I had to go to the "Easy Save > Auto Save > Prefabs" and select the scripts I want to save and the fields in which I am interested.

Currently I have everything more or less working, but I have a couple of questions:
- Sometimes, some prefabs that I select from the previous menu are unselected when I close the scene. I make sure that I press "save", but it happens really often and with the same prefabs. Do you know what can be causing this?
- I would like to be able to create different slots for saving game, how I could change the path in runtime or have different paths already configured so when I click a slot, one of this is selected?

Thank you in advance.

Cheers!

Re: Persist Scriptable Objects between scenes

Posted: Sat Sep 26, 2020 10:41 am
by Joel
Hi there,

Glad you managed to find the solution.
Sometimes, some prefabs that I select from the previous menu are unselected when I close the scene. I make sure that I press "save", but it happens really often and with the same prefabs. Do you know what can be causing this?
I've not heard of this happening before. The only time I can imagine that this would happen is if you select it when you're in playmode, as Unity doesn't persist changes when you're in playmode. However, if this isn't the case then if you're able to private message me a basic project and instructions to replicate it I'll be happy to look into it further.
I would like to be able to create different slots for saving game, how I could change the path in runtime or have different paths already configured so when I click a slot, one of this is selected?
There's information on changing the path of the Auto Save's file at the bottom of the Auto Save guide here:
https://docs.moodkie.com/easy-save-3/es ... hout-code/

Hope this helps!

All the best,
Joel

Re: Persist Scriptable Objects between scenes

Posted: Mon Oct 19, 2020 5:11 pm
by JoseHawk
Hello,

After having solved everything and be working perfectly in development, when generating a build, the scriptable objects are broken.

The error I got:

Reference for Code.ScriptableObjects.Collectables.ItemData with ID XXX could not be found in Easy Save's reference manager. Try pressing the Refresh References button on the ES3ReferenceMgr Component of the Easy Save 3 Manager in your scene.

Do you know what can be happening?

Thank u in advance!