Hey, Im trying to save the position of my Player Gameobject and I have created two simple save and load methods that execute on button press for that.
public GameObject player;
public void Save ()
{
ES3.Save<Vector3>("playerPosition", player.transform.localPosition);
}
public void Load()
{
player.transform.localPosition = ES3.Load<Vector3>("playerPosition");
}
But for some reason this is not working at all. Sometimes just nothing happens and sometimes I get an error saying the key playerPosition does not exist but the player never acctually changes its location.
Thanks in advance!
Cant save the position of a GameObject
Re: Cant save the position of a GameObject
Hi there,
All the best,
Joel
This is because you're not checking whether save data exists before loading, or giving the ES3.Load method a default value to return if the data doesn't exist.Sometimes just nothing happens and sometimes I get an error saying the key playerPosition does not exist but the player never acctually changes its location.
All the best,
Joel
Re: Cant save the position of a GameObject
Hey,
I have adjusted my code as you told me:
public GameObject player;
public Vector3 defaultValue;
public void Save()
{
ES3.Save("playerPosition", player.transform.localPosition);
}
public void Load()
{
player.transform.localPosition = ES3.Load("playerPosition", defaultValue);
}
And while I dont get any errors now, the players Position still does not change when I load.
Thanks for helping!
I have adjusted my code as you told me:
public GameObject player;
public Vector3 defaultValue;
public void Save()
{
ES3.Save("playerPosition", player.transform.localPosition);
}
public void Load()
{
player.transform.localPosition = ES3.Load("playerPosition", defaultValue);
}
And while I dont get any errors now, the players Position still does not change when I load.
Thanks for helping!
Last edited by stucky8 on Sun Apr 11, 2021 1:43 pm, edited 1 time in total.
Re: Cant save the position of a GameObject
Hi there,
Please could you replicate this in a new project with a basic scene and private message it to me with instructions?
All the best,
Joel
Please could you replicate this in a new project with a basic scene and private message it to me with instructions?
All the best,
Joel