So in one of my games i tried using Playerprefs to make a highscore system. And in this i need to store in playerprefs 8 int and 8 float.
So everything was working smoothly with 1 playerpref but then i got to 2 or more and i had this problem.
If i set more than 1 playerprefs, they are all equal to the same value. They don't have the same key, nor the same value. But the last playerpref that is saved replace all the others. And if it's a different type like a float, it reset to 0 my ints.
So i made another project to see what was wrong and i still encounter the same problem.
Simple project, 3 buttons :
- 1 : add 1 to an integer (ScoreB1)
https://puu.sh/CCnEp/cb8b637c85.png- 2 : add 1 to an integer (ScoreB2)
https://puu.sh/CCngb/1a5b1dedbb.png- 3 : a save button that set the playerprefs (save the score B1 and B2 in 2 differents keys)
https://puu.sh/CCnFT/e95c27549c.png4 ui text :
1 - Show the value of ScoreB1
2 - Show the value of ScoreB2
3 - Show the value of the storedKey equal to B1 (the highscore, stored when you exit the game)
4 - Same as 3 but for B2
https://puu.sh/CCniw/84694e4c23.pngBut if i set the values to ScoreB1 = 15 and ScoreB2 = 7
https://puu.sh/CCnjv/597ed15e4b.pngthen save it :
https://puu.sh/CCnkI/bb99beb08c.png we can see the 2 differents keys and the 2 differents values in the set int.
But when i restart the game :
https://puu.sh/CCnPB/80e4699b44.png both of my keys have a same value in the Get. (and on the ui text
https://puu.sh/CCnlX/25368e5125.png)
Only thing i found is a guy from reddit (4 YEARS AGO) that had the same problem.
https://www.reddit.com/r/Unity3D/comments/27h5ea/need_a_little_help_with_high_score_system/Problem 1: it seems like Playerprefs are only made for saving 1 variable of each type. Even though my high scores all use separate keys, if I call Playerpref Set Int it will set the int value for ALL of my Playerpref Int. Therefore, if I set a new high score in one game mode and then go play a different game mode, it will treat both high scores as 1. So I get the same high score value even though they are different game modes and using different keys.
I don't know what to do, maybe i'm setting it wrong.
https://puu.sh/CCnA8/66bec0bdf2.png