Hello guys. I am currently messing around with the PSM Preview release and i am wondering how saving data is handled. I currently have written a small system that creates a JSON string of data from some predefined arrays, that is then saved locally using the path returned from Application.persistentDataPath. My publishing license is currently pending approval at Sony, so i cannot currently test if this works properly on the actual device. So if anyone has some experience on how data saving is handled, i would love to hear your experiences.
In Unity, I've usually used PlayerPrefs for singular variables (strings/ints/floats) since it's like 1-3 lines of code at most. ArrayPrefs for bigger amounts. That seems to work pretty well. PlayerPrefs confirmed working on my Vita. (If it was easier, I would probably just save files like you.)
Both PlayerPrefs and Application.persistentDataPath are supported. Application.persistentDataPath maps to /Documents - this folder is persistent between runs Application.temporaryCachePath maps to /Temp - this folder may or may not be cleared between runs PlayerPrefs is in fact serialized to file under Application.persistentDataPath. There is a limitation on depth of the directory structure - IIRC it has a maximum depth of 6 (ie. /Documents/1/2/3/4/5/6.txt)
Is system.io and system.xml working on Unity PSM? I know it doesn't work on native SDK but haven't tried out yet on Unity PSM. Thanks,
I haven't tried System.XML specifically, but I expect it to work. System.IO definitely works (it's limited to the read/write to /Documents and /Temp, and read-only from /Application).
If System.IO works I guess system.XML should too, going to check it out soon. [EDIT] Both works fine. Already deploying our game to the Vita!
I can also confirm that PlayerPrefs and Application.persistentDataPath are supported. My game currently uses both and it works
My game uses a large quantity of files loaded dynamically from disk, so I tried to bundle them by opening the .psdp packages with 7zip and pasting my file hierarchy in there like I do on PC builds, but the Publishing Utility for Unity then started failing to deploy the package back to the PSVita. After a bit of digging around it looks like I hit the 6 levels of depth limitation that was mentioned here, but the message displayed is pretty obscure, so I'm sharing it in case someone else comes across it :
Btw, you don't have to dig through the .psdp file, if you simply Build (instead of Build Run) Unity builds everything into folders/sub-folders where you can add/arrange new folders/files and then create a .psdp file out of that using the Publishing Utility.
Oh, thanks for the tip, I'll try that ! I thought you were supposed to "extract pdsp package" from the publishing utility, then sort of rebuild it through the "create pdsp" option, but I couldn't get it to work that way.
Appreciate the confirmation eriQue! Now i just need my license to get approved so i can test the system
No you don't have to. We for instance have a database distributed around sub-folders that we install at build time.
Player prefs does not work on vita for me, they are finished games that works fine on android, iOS, mac and pc. (been released for over a year) Its just the usual player prefs name or rank saving string or int etc, am i missing something? Can anyone shed some light on this for me, heres a snippet as i know someone will ask. Edit: now when i start the game my ranks at 4, but nothing else seems to save, and rank a new rank won't save, not sure whats going on haha
Thanks will give that a try, gave it a quick read and it makes sense, says set ints and strings may not be saved correctly if the app is force closed or crashes (swiping the vita app to close may be the problem) will post whether it works or not so you guys as well as myself are more wiser about unity-vita.
This is just a guess, but - could it be that you are storing some data, and then re-deploying the game from the editor - and then your data is not there? Then this is expected (* see below) since the editor will uninstall the application, thus removing your PlayerPrefs, before installing the new version of the application. (*) This is only the case with the Public Preview version of Unity-for-PSM. The next version will have this fixed, and subsequent "Build&Run"'s from the editor will preserve the PlayerPrefs contents.
I have not been rebuilding like you suggested, but i have not yet tried the PlayerPrefs.Save() to see if that fixes my problem, if it persists i'l test a blank new project and submit a report on it if it does. Edit: Adding "PlayerPrefs.Save();" after my set prefs now saves the data fine
Er what? Do you mean that the Build and Run process will simply update the existing version of the app on the device as opposed to uninstalling it and then dropping a fresh build. I ask because it's expected behaviour on every mobile/desktop device that an uninstall removes transient data. Also, if this is the case, then I hope that there is a toggle to turn on clean installs again.
Android and iOS, build and run updates the app (keeps saved data) it does not uninstall and remove save data, then put a fresh copy on >_<
Uninstall yes, but that's not what we're talking about here. Build&Run should preserve PlayerPrefs and similar data. This is what happens with desktop (saved to the registry on Windows) as well as mobiles (stored using SharedPreferences object on Android for example). Build&Run preserving data is needed to 'guarantee' you can update your title in the wild without losing user progress or similar.
Any chance you could provide a small repro project, code and/or steps to reproduce the symptoms you're seeing? If so, please file a bug through the bug reporter (Help -> Report a bug, in the editor). Thanks.
I also have a cuestion about saves so ill ask here is the method described here http://unity3d.com/learn/tutorials/...ining-archive/persistence-data-saving-loading supported or working for PSM?
Yes installing an APK or an apple app over an existing install will keep the data. However, given that build and run is for testing purposes only. I would have expected it to uninstall the old version first as not doing so can lead to corrupted data and an app failing to run correctly on the device. Personally I never actually use build and run except with PSM simply because I've had way too many issues with apps seemingly being broken after a build and run but, working just fine after a fresh install.
If installing "on top" of a previous installation (effectively updating) could lead to corrupted data, then that would be extremely critical since it could also affect the update mechanism of a released title. That said - the mechanism in the Public Preview is in fact to uninstall-before-install - so there is virtually no difference between "doing a fresh install" and using "Build&Run". The reason for this was precisely because of an issue with the install command in the PSM Tool Set for Unity version for the Public Preview. This problem as since been fixed. The Official Release will however use the expected behavior from other platforms, and install "on top" of the previous installation (keeping any files written to /Documents (such as PlayerPrefs) etc.)
Yes - PlayerPrefs is supported. One thing to note is that PlayerPrefs.Save() must be called manually to serialize the changes to persistent storage. Application.persistentDataPath is also supported with PSM. So is Application.temporaryCachePath. With PSM, PlayerPrefs is in fact storing its contents using Application.persistentDataPath (which equals /Documents)
Thank you, but the method used in the video don't use playerprefs, it use binary formatter and the lenguage serialization (not unity serialization) im sure my really bad english is confusing you lol sorry about that its my 3rd lenguage and im not so good at it. Any way my question is if the serialization used in the video and binary formaters can be used to make a save system for PSM. Not using playerprefs. Thanks again.
The video mentions storing data using PlayerPrefs and manual serialization to Application.persistentDataPath (and the benefit of using the latter). Both of which I already mentioned in the previous post are supported with PSM.
Thank you, well as im not that good speaking english i need to read answers for dummies just like that =) sorry to be a bother to you. And thanks again.