Save GameObject Manually

Discussion and help for Easy Save 3
Post Reply
erlemaitre
Posts: 8
Joined: Fri Jan 08, 2021 11:44 am

Save GameObject Manually

Post by erlemaitre »

Hello,

I created a very simple game where I have a cube, and I change its color at runtime like so:

Code: Select all

cube.GetComponent<MeshRenderer>().material.color = color;
I also have two buttons to save and load my cube. I save and load like this:

Code: Select all

public void SaveCube(GameObject cube) {
    ES3.Save("cube", cube);
}

public void LoadCube(GameObject cube) {
    ES3.LoadInto("cube", cube);
}
I also added an Easy Save 3 Manager to my scene.
But my cube isn't saved or loaded... :? What am I doing wrong ?
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Save GameObject Manually

Post by Joel »

Hi there,

Please could you private message me a basic project which replicates this?

Also are you getting any errors or warnings to console?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
erlemaitre
Posts: 8
Joined: Fri Jan 08, 2021 11:44 am

Re: Save GameObject Manually

Post by erlemaitre »

Hi,
I sent you my Unity project, and I don't get any error or warnings in the console.

Thank you,
Eric
User avatar
Joel
Moodkie Staff
Posts: 4826
Joined: Wed Nov 07, 2012 10:32 pm

Re: Save GameObject Manually

Post by Joel »

Hi Eric,

Thanks for sending that over. I'm getting the following warning, so you might want to check that your error console is configured correctly:
Reference for UnityEngine.Material with ID 5165723412715100437 could not be found in Easy Save's reference manager
This happens because when you access a MeshRenderer's 'material' field to change it's colour, it creates a new instance of that Material. This Material instance will no longer exist when you exit the scene or exit play mode.

In this case you would either need to use the 'sharedMaterial' field, or you would need to save and load the colour separately. E.g.

Code: Select all

public class SaveManager : MonoBehaviour
{
    public void SaveCube(GameObject cube) {
        ES3.Save("material", cube.GetComponent<MeshRenderer>().material.color);
        ES3.Save("cube", cube);
    }

    public void LoadCube(GameObject cube) {
        ES3.LoadInto("cube", cube);
        cube.GetComponent<MeshRenderer>().material.color = ES3.Load<Color>("material");
    }
}
I also recommend deleting your save data after making any changes by going to Tools > Easy Save 3 > Clear Persistent Data Path.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
erlemaitre
Posts: 8
Joined: Fri Jan 08, 2021 11:44 am

Re: Save GameObject Manually

Post by erlemaitre »

Thank you very much!

I only tried this on a real device, I guess that's why I didn't get the errors in the Xcode console.
Thank you for your time and the great tool,

Eric
Post Reply