Page 1 of 1

Save GameObject Manually

Posted: Fri Jan 08, 2021 11:51 am
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 ?

Re: Save GameObject Manually

Posted: Fri Jan 08, 2021 12:27 pm
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

Re: Save GameObject Manually

Posted: Fri Jan 08, 2021 5:06 pm
by erlemaitre
Hi,
I sent you my Unity project, and I don't get any error or warnings in the console.

Thank you,
Eric

Re: Save GameObject Manually

Posted: Sat Jan 09, 2021 8:46 am
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

Re: Save GameObject Manually

Posted: Mon Jan 11, 2021 11:19 am
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