In my current project I am developing a game saving system and I have encountered a problem where in some cases when I save the game and re-load it the player will not be loaded in at the correct position.
I've printed the position that is loaded in from file to the console to see if it's being changed and it's not.
Is there anything i'm not seeing?
For reference here's the two methods I use when loading the game:
public void LoadData() {
if (File.Exists(filename)) {
byte[] soupBackIn = File.ReadAllBytes(filename);
string jsonFromFile = encryption.Decrypt(soupBackIn, JSON_ENCRYPTION_KEY);
copy = JsonUtility.FromJson<SaveData>(jsonFromFile);
print(copy.playerPosition);
DataToLoad();
}
}
private void DataToLoad() {
player.transform.position = copy.playerPosition;
player.transform.rotation = copy.playerRot;
player.playerHealth = copy.playerHealth;
player.agility = copy.agility;
player.attack = copy.attack;
player.defense = copy.defense;
player.strength = copy.strength;
for (int i = 0; i < copy.inventory.Count; i++) {
inv.AddItem(copy.inventory[i].id);
}
}