An Easy Save 3 Manager is required to save references

Discussion and help for Easy Save 3
Post Reply
RickyP602
Posts: 5
Joined: Thu May 11, 2023 1:33 am

An Easy Save 3 Manager is required to save references

Post by RickyP602 »

Hello,
I was running into some problems saving data with the auto save functionality of EasySave3 so decided to tackle the problem from code and have had much better success. Although I am still running into an issue. Occasionally when saving this error gets thrown:

Code: Select all

InvalidOperationException: An Easy Save 3 Manager is required to save references. To add one to your scene, exit playmode and go to Tools > Easy Save 3 > Add Manager to Scene
ES3Writer.WriteRef (UnityEngine.Object obj) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:239)
ES3Types.ES3Type_GameObject.WriteObject (System.Object obj, ES3Writer writer, ES3+ReferenceMode mode) (at Assets/Plugins/Easy Save 3/Scripts/Types/Unity Types/ES3Type_GameObject.cs:27)
ES3Writer.Write (System.Object value, ES3Types.ES3Type type, ES3+ReferenceMode memberReferenceMode) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:228)
ES3Writer.WriteProperty (System.String name, System.Object value, ES3Types.ES3Type type, ES3+ReferenceMode memberReferenceMode) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:295)
ES3Writer.Write (System.Type type, System.String key, System.Object value) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:142)
ES3Writer.Write[T] (System.String key, System.Object value) (at Assets/Plugins/Easy Save 3/Scripts/Writers/ES3Writer.cs:129)
ES3.Save[T] (System.String key, T value, ES3Settings settings) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:110)
ES3.Save[T] (System.String key, T value) (at Assets/Plugins/Easy Save 3/Scripts/ES3.cs:71)
LevelSpawner.OnDestroy () (at Assets/Scripts/LevelSpawner.cs:32)
There is an Easy Save 3 Manager in all 4 scenes of my project and I have went to each scene and added a reference to the manager for the script it is complaining about but it will throw this error for any ES3.Save() call I make in other scripts as well. Interestingly it is not consistent:

https://i.imgur.com/vOKZbhv.png

The above example took 3 tries to get it to throw the error. Sometimes it will throw it several times in succession.

Code for the level spawner:

Code: Select all

public class LevelSpawner : MonoBehaviour
{
    GameObject spawnPoint;
    GameObject character;
    private void Awake()
    {
        if (ES3.FileExists())
        {
            this.spawnPoint = ES3.Load<GameObject>("LevelSpawner");
        }
    }
    void Start()
    {
        if (spawnPoint == null)
        {
            spawnPoint = GameObject.FindGameObjectWithTag("Spawn");
        }
        character = GameObject.FindGameObjectWithTag("Player");
        if( character != null)
        {
            character.transform.position = spawnPoint.transform.position;
        }
    }
    private void Update()
    {
        this.transform.position = character.transform.position;
    }
    private void OnDestroy()
    {
        Debug.Log("Saving Level Spawner Transform");
        ES3.Save("LevelSpawner", spawnPoint);
    }
}
User avatar
Joel
Moodkie Staff
Posts: 4872
Joined: Wed Nov 07, 2012 10:32 pm

Re: An Easy Save 3 Manager is required to save references

Post by Joel »

Hi there,

This is likely because you're using OnDestroy but there's no guarantee that the manager won't be destroyed before your OnDestroy method is called.

In this case I would attach a script with OnDestroy to the Easy Save Manager and get it to save your spawn points, rather than getting spawn points to save themselves.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
RickyP602
Posts: 5
Joined: Thu May 11, 2023 1:33 am

Re: An Easy Save 3 Manager is required to save references

Post by RickyP602 »

yep that works 100% of the time. Thank you!
Post Reply