PlayerPrefs loading data inconsistently
I've looked at a lot of forums regarding PlayerPrefs but nothing about inconsistent data loading. I've used a tutorial to store the transform and rotation of the player upon a save, and to load them back in when the scene loads. I know how PlayerPrefs work, and I've made (what should be) a simple loading/saving code, but I don't know what I've done wrong which would make it so that it only loads in the position and rotation sometimes.
I've attached my code here, and the problem is that every time I load, there is around a 25% chance rotation OR position load, and a lower chance that NEITHER position or rotation load, and a high-ish chance position AND rotation load correctly.
What is it that I'm doing wrong? I feel like I'm going nuts, because sometimes it will work, and sometimes it won't. I'm using LoadSceneMode.Single every time I need to Load data as well. I'm just so confused why sometimes parts of the data are missing or not referenced.
Answer by unity_1bircheth · Mar 21 at 06:45 PM
Also, if you see extraneous variables in my SaveData script that's because I was doing it a different way before, so just excuse those.
UPDATE: If anyone sees this, I may have found a fix. I added a line at the very top of my Save() method which is PlayerPrefs.DeleteKey("PlayerTransform").; The problem I was experiencing may have been that there was a clash between the initial player transform values and the saved player transform values, though I have no clue why. I've now made it so that it is erased each time before they are rewritten.