I'm looking at a social interaction app with some game play. I want to create forms and screens so users/players can create personal profiles they can ultimately share over bluetooth/wifi/3G etc. Where and how to I save the data input in the forms? I've found stuff on the player prefs file, but that seems to relate to web games only. Can someone point in the right direction? Examples? Code snippets?
Answer by A Lee
Dec 14, 2010 at 02:19 PM
Player Prefs aren't just for web games. They are good for storing data that you do not want to lose between game sessions. However, they can only save strings, floats, and integer variables, so if you need booleans, you'd be best to use an integer as a flag.
The only thing that you need to be careful of when using Player Prefs is that you do not try to access a null variable. If you do this, the Unity editor will not pick up on it and the game will seem fine, until you build it to a device and you get a SIGBUS error. The way I would go about doing it to prevent this is have some class that initializes all Player Prefs on the first scene to ensure that they all exist when they are needed. For example:
This will check to see if the Player Prefs exists, and if it doesn't, it will be created. It is basically a safeguard against SIGBUS errors.
So for what you are looking to do, you can simply save the input from your text fields into Player Prefs, and they can be accessed during any game session.
Hope this helps
Brilliant. Much appreciated.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users post good questions and use the site effectively we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
Answers and Comments
No one has followed this question yet.
How to save data on iOS?
Level builder for iphone
capture the screenshot to iPhone photo gallery
Load from Xml on Iphone and Android
on iphone is persistentDataPath the equivalent of Documents?