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\$
  • \$\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 '17 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 '17 at 23:41
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\$
  • \$\begingroup\$ You can also mark this as the answer ;) \$\endgroup\$ – Zhaph - Ben Duguid Feb 21 '18 at 18:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.