Reference could not be found in reference manager

Discussion and help for Easy Save 3
Post Reply
Simplemole
Posts: 7
Joined: Tue Aug 23, 2022 3:34 pm

Reference could not be found in reference manager

Post by Simplemole »

Hi, when I save GameObject and load it again, it is loaded but Sprite in Sprite renderer is missing (other variables and also my scripts looks to be loaded correctly). I am getting warning "Reference for UnityEngine.Sprite with ID 6429260329939571930 could not be found in Easy Save's reference manager. If you are loading objects dynamically (i.e. objects created at runtime), this warning is expected and can be ignored."

I am attaching saved file where you can in see in Sprite Renderer that

Code: Select all

"sprite" : {
		"_ES3Ref" : "6429260329939571930"
},
This is how I am saving the file (result attached):

Code: Select all

        public void SaveColonists(string saveName)
        {
            List<GameObject> saveGOs = new();
            foreach (Colonist c in _colonists)  //_colonists is monobehaviour script
            {
                saveGOs.Add(c.gameObject);
            }
            ES3.Save(SAVE_COUNT, saveGOs.Count, saveName);
            ES3.Save(SAVE_LIST, saveGOs, saveName);
        }        
This is how I am loading (maybe not relevant as I think that problem is when saving)

Code: Select all

        public void LoadColonists(string saveName)
        {
            List<GameObject> loadGOs = new();            
            int itemsCount = ES3.Load<int>(SAVE_COUNT, saveName);
            for (int i = 0; i < itemsCount; i++) 
            {
                loadGOs.Add(SpawnColonist(new Vector2Int(0, 0)).gameObject);    //SpawnColonist instantiate prefab with colonist script, sprite renderer
            }
            
            ES3.LoadInto(SAVE_LIST, saveName, loadGOs);  //game objects are loaded to prepared instances - you use this approach in one of the tutorials and it fits to what I want to achieve
            foreach (GameObject go in loadGOs)
            {
                _colonists.Add(go.GetComponent<Colonist>());
            }
        }

Can you please advise me how to solve it/what I am missing?
Thank you!
Attachments
inspector after loading the object - sprite is none
inspector after loading the object - sprite is none
2022-08-24_20h11_35.png (51.19 KiB) Viewed 1121 times
Save1_colonists.txt
saved file
(4.26 KiB) Downloaded 76 times
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Reference could not be found in reference manager

Post by Joel »

Hi there,

This usually means one of two things:
  1. Your Sprite is not referenced in your scene at runtime, or is referenced too deeply for the reference manager to find it, meaning a reference is never added to the manager prior to runtime.
  2. Your Sprite is created or modified at runtime, meaning the instance will only exist in that session.
If it's #1, you can right-click your Sprites while not in playmode and select Easy Save 3 > Add Reference(s) to Manager. This will manually add them to the manager to ensure that a reference can be found.

If it's #2, you would need to save your Sprite(s) using a separate ES3.Save call to ensure that they are saved by value, and ensure that you load these Sprites before loading anything which references them.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Simplemole
Posts: 7
Joined: Tue Aug 23, 2022 3:34 pm

Re: Reference could not be found in reference manager

Post by Simplemole »

Hi Joel, thank you very much for the response, I am instantiating all GameObjects on runtime, so it is #2.
I was digging a bit into how exactly ReferenceManager works when you work with GameObjects in runtime, can you please confirm (or correct me or send me the link where it is discussed/described) the following:

I have two GameObjects, instantiated from prefab (marked as ES3) with two scripts on them (all 3 scripts are ES3Serializable) arrows shows how references are held:
2022-08-25_15h19_07.png
2022-08-25_15h19_07.png (9.89 KiB) Viewed 1113 times
When I ES3.Save Colonist1 and then Building1 (save by reference) and then ES3.Load Colonist1 and Building1
1. Colonist Script will be missing the reference to "living place" (Building Script) - because Colonist1 was loaded before Building1 (and in that time Building Script didn't exist)?
2. Building Script will have reference to "occupants" (Colonist Script) because in that time Colonist Script already existed?
3. Inventory Script will be saved and loaded correctly for both objects, but there will be warning 'Reference for UnityEngine.Sprite with xxx could not be found in Easy Save's reference manager.'

I am currently workaround #1 by saving buildingID instead of reference and loading it lazily, but I am ready to use a better way if there is one.

Thank you!
Best regards, Jakub
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Reference could not be found in reference manager

Post by Joel »

Hi there,

Sorry, I should clarify. Instantiating the GameObject at runtime is different to creating the Sprite itself at runtime. Try #1 and see if this resolves your issue, otherwise we'll dig a bit deeper.

The other aspect you mention seems to be a different issue around the order of saving and loading. It's not possible to load a reference to something which doesn't yet exist, so load order is important. If there's a cyclic reference (i.e. two objects refer to each other) then the way to resolve this is to load twice: once to create the instances and another time to assign the references.

Also just one thing to check, have you followed the Saving and Loading Prefab Instances section here?
https://docs.moodkie.com/easy-save-3/es ... 0instances

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Simplemole
Posts: 7
Joined: Tue Aug 23, 2022 3:34 pm

Re: Reference could not be found in reference manager

Post by Simplemole »

Hi Joel, thank you for clarifying, loading twice seems like an elegant way how to solve cyclic references. The original problem was solved by adding all sprites I have to Add References to Manager.
Great support, thank you!
LelandGreen
Posts: 5
Joined: Tue Aug 23, 2022 11:37 am

Re: Reference could not be found in reference manager

Post by LelandGreen »

Hi Joel,

I've been reading some threads here and I think you have fantastic support.

That's an ingenious way to load objects with cyclic references.

I'm going to read a little more with my coffee. Then off to do a little more work with EasySave.

Best wishes,
Leland
User avatar
Joel
Moodkie Staff
Posts: 4852
Joined: Wed Nov 07, 2012 10:32 pm

Re: Reference could not be found in reference manager

Post by Joel »

LelandGreen wrote: Fri Aug 26, 2022 10:25 am Hi Joel,

I've been reading some threads here and I think you have fantastic support.

That's an ingenious way to load objects with cyclic references.

I'm going to read a little more with my coffee. Then off to do a little more work with EasySave.

Best wishes,
Leland
Thanks Leland, really appreciate the kind words :)

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Post Reply