I have tried to save using player prefs in the Andriod app, but it does not save on the phone, anyone able to do this with the andriod and Unity?
I ported my iPhone app over, and did nothing to any of my playerprefs code and its all working just fine on the Nexus One.
PlayerPrefs are working fine but PlayerPrefs.DeleteAll is not. We have just worked around that one.
In my code, I am writing to the playerprefs and can load and use it only while the game is running, when I quit the game the subsequently reload it, the playerprefs is empty and I canât retrieve the last saved game data. So basically what I have right now, is
void savePrefs()
{
PlayerPrefs.SetString("data", _data);
}
void loadPrefs()
{
PlayerPrefs.GetString("data");
prepareGameItems();
}
_data is defined as a string and it does save and load in, but as I mentioned, it will only do it for the active game and wile the game is loaded, if I quit the game, the PlayerPrefs value for data is emptyâŚ
Is it possible for me to post my compiled package for someone else to test on their Android?
I have taken the save/load and added it to my XMLDemo code, I can post the package if anyone can simply deploy it up to their Andriod phone and test it, once loaded, simply use the âBuild Blocksâ then use the âSave Prefsâ button, a new button will show up that allows you to use the saved values for setting them âSet Loaded Gameobjectsâ, the thing is, since this exists in the scene, that means that the prefs did save. The way to check this, is to click that button, then touch the âclear blocksâ button at the top, then touch the âload prefsâ and the blocks will load up and the âSet Loaded Gameobjectsâ will appear again which states that the load worked. Once you have done this, simply quit using the âQuitâ button, then go back in the game and click on âLoad Prefsâ and nothing will load. ⌠âŚ
I really need this confirmed by someone else besides myself so that I know that I am not going mad.
In the code you included there, the return value of GetString isnât being assigned to anything. Did you mean for it to be assigned back to that same âdataâ variable?
Yes⌠good catch on the example, I have that in my game code but not what I just converted, that section of code should read:
void savePrefs()
{
prepData();
PlayerPrefs.SetString("data", _data);
}
void loadPrefs()
{
_data = PlayerPrefs.GetString("data");
prepareGameItems();
}
I need to stop rushing to get examples of problems ready.
Another question about this, when you update your game and push it out, how is the PlayerPrefs value kept without purging when an update is pushed to the phone since technically I think this âsecured areaâ for the app is purged and rebuilt from an update? So once I do get this going correctly, what is stopping my saved games from being lost on the persons phone when I push out a new build of the same application?
It is possible to uninstall/reinstall an app while still keeping stuff like player prefs, cache etc. This is actually what Unity does when you select Build&Run, and I assume this is how the PackageManager handles an updated version from the Android Market too. The only caveat is that the updated version needs to be signed with the same key, presumably because this key is somehow involved in managing the application specific files.
The key that Unity generates is good enough for this purpose right?
Whenever I load a new build on my NexusOne, the playerPrefs are always cleared - even when using the same key in the publishing settings. I also pushed an update to Marketplace and am getting support emails from players saying their progress has been cleared. Any tips on what might be going wrong?
Any ideas erique? Iâd like to get this fixed for the next update as we are getting negative comments in Google Marketplace about the update erasing playerâs progress.
When doing build&run from the editor and you have keysigning enabled (ie not debug key) the editor will do a clean install (this is to prevent trying to update binaries signed with different keys (that doesnât work). But if you create two .apks (ie version 1.0 and version 1.1) and install them after each other manually the playerprefs should be kept. If they donât please report that bug. We are not actively reseting the playerprefs, so either something changed in the update mechanism, or itâs something else entirely.
Thanks erique Iâll give that a go and let you know what happens!
Update:
Using build run in the editor with the debug key does keep the PlayerPrefs (as you predicted). I then created two apks (using the same non-debug keys) v 1.0 and v 1.0.1. I was able to load the 1.0 version onto the NexusOne using adb, but it wouldnât let me replace it with the new apk, e.g. in Terminal:
SyBookPro:~ simonedis$ adb install Documents/Android/FinalApps/CrazySnowboard/Marketplace\ 1.0/Snowboard.apk
918 KB/s (20930376 bytes in 22.256s)
pkg: /data/local/tmp/Snowboard.apk
Success
SyBookPro:~ simonedis$ adb install Documents/Android/FinalApps/CrazySnowboard/Marketplace\ 1.0.1/Snowboard.apk
1246 KB/s (21194695 bytes in 16.602s)
pkg: /data/local/tmp/Snowboard.apk
Failure [INSTALL_FAILED_ALREADY_EXISTS]
âŚso I canât really check to see if it is saving the PlayerPrefs. Is there another way to install the update?
Update 2:
I found the âadb install -râ command which installed the update successfully.
âŚand more importantly I found my error, which was the PlayerPref save name had been changed in my code - so the good news is that Unity PlayerPrefs is working perfectly for updates. My bad! - thanks for your patience and help!
I have run across a problem on my galaxy s that involves PlayerPref never saving anything.
Itâs still very hazy what triggers it, as Iâve tried a lot of stuff.
Works on other phones, and used to work on my galaxy s too, even with the version that is now bugging.
Weird.
are you on android 2.1 or 2.2?
On Android 2.2 ⌠Sorry about so slow reply. I must turn on some email-notifications so I wonât post&forget.
I made a custom PlayerPrefs class to allow faster saving on Android.
As it uses a different way of saving data, it would probably be a good work-around for your issue.
I seem to have a weird bug, which âsometimesâ on âsome devicesâ leads to PlayerPrefs not saving anything. has anyone else experienced this or has any idea how to fix that bug? The really bad thing about the bug is that although it seems to appear regularly (approx. 1% of our users) I havenât been able to reproduce it once with any of our devices, so Im stabbing in the dark here. For starters I would be interested in what circumstances would prevent the PlayerPrefs from saving anything? Would insufficient space would lead to data loss? Could it be a permission thing? I have no idea. One user though reported it went away after reintstalling, but that doesnât always seem to help. Also I had users reporting it stopped working after the last update, but then again it still works for the majority (99%) of the users.
Tried that custom PlayerPref class of yours and like the regular one, itâs not saving anything to my Android phone. By now Iâm really desperate to get the prefs to work, because without it I canât release my game because Iâm linking the Android prefs to an online database.
@ , Iâm guessing there must be something specific in your project because we donât have any bug reports regarding player prefs that hasnât been solved. Please file a bug report and attach a repro project so that we can have a look at whatâs going wrong.
I have figured it out. There was totally nothing wrong with the PlayerPrefs class at all. The problem came from an other part in the code that I figured out now. I noticed that in the database the DateTime stamp stayed the same with each new PlayerPrefs made on the devide, so I figured something was stored in PlayerPrefs but an other thing went wrong. After an hour of trial & error I found out that the WWW.Progress would never reach a full 1 (completed, which I checked in the code) on the Android device. Only checking if WWW.progress!=null was enough to get the whole thing running on my phone! Now itâs time to get into some further testing on my phone.