0
\$\begingroup\$

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);
    }
}
\$\endgroup\$
2
  • \$\begingroup\$ Just noting the rollback. We dont mark the question, itself, as solved. Instead, mark your answer as accepted. You will need to wait a couple of days before you can accept your own answer. \$\endgroup\$
    – Gnemlock
    Feb 16, 2017 at 23:25
  • \$\begingroup\$ Yeah, I tried I just didn't want people to waste their time clicking on this question but that's fine and noted for the future :) \$\endgroup\$
    – Yatoniea
    Feb 16, 2017 at 23:41

1 Answer 1

1
\$\begingroup\$

I had a NavMeshAgent attached to my player from a previous prototype of a movement type for the game and it was interfering with where the player was positioned.

\$\endgroup\$
1
  • \$\begingroup\$ You can also mark this as the answer ;) \$\endgroup\$ Feb 21, 2018 at 18:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .