A distinction of what PlayerPrefs is
From what I understand, a "PlayerPref" is supposed to save data relevant to the player. However, I'm somewhat confused by the name. Is it supposed to save the player's system preferences, or is it used for more than that (e.g. "Player Score")?
Answer by Chiroculon · Apr 06, 2017 at 12:16 PM
@017Bluefield The word "Player" here refers to the Unity Player, so in the context of your question, that would be the system preferences.
Does "system preferences" include things like Player Score? Here's an example from the documentation.
I see what you mean.
I looked around some more in the documentation and found this.
It looks like it's meant to contain anything that you would want to save between sessions. I guess it's meant for browser games; kind of like cookies.
You could also look at it different way: the word „player“ here refers to system user. For example on Windows, it's one single user (single user account). On Android (AFAI$$anonymous$$ it's not multi-user environment), it's whole system (for example one physical phone).
To answer whether it include things like Player Score, you should answer first whether you're O$$anonymous$$ that under one Windows user / Android device owner can be only one player. If yes, then PlayerPrefs can include Player Score. If no, then you need your own system for storing player data (which can still use PlayerPrefs with keys like „{player-id}/score“). In that case, „system preferences“ should store things like which player played last.
(And one side note: after a few projects, I don't store single values in PlayerPrefs anymore. Ins$$anonymous$$d, I serialize whole „player data“ to json and then store whole json string to single PlayerPrefs value.)
Answer by OfficialCoatsee · Apr 09, 2017 at 06:37 AM
I have used Player.prefs to store local user information, so it can be used for that, as well as client settings. Basically anything you want to store and retrieve you can set via Player.prefs.
My Start() method contains a little PlayerPrefs script to assess where exactly the Character is at, but you can use it for whatever you like.
if (PlayerPrefs.GetString ("character_" + username) != "") {
woodcutting = PlayerPrefs.GetInt ("woodcutting_level_" + username);
woodcutting_xp = PlayerPrefs.GetInt ("woodcutting_xp_" + username);
woodcutting_xp_required = PlayerPrefs.GetInt ("woodcutting_xp_required_" + username);
attack = PlayerPrefs.GetInt ("attack_level_" + username);
attack_xp = PlayerPrefs.GetInt ("attack_xp_" + username);
attack_xp_required = PlayerPrefs.GetInt ("attack_xp_required_" + username);
Vector3 loaded_pos = new Vector3(PlayerPrefs.GetFloat ("character_pos_x_" + username), PlayerPrefs.GetFloat ("character_pos_y_" + username), PlayerPrefs.GetFloat ("character_pos_z_" + username));
transform.position = loaded_pos;
}
Of course, there are many different ways of doing this.
PlayerPrefs has many different uses. Depends how creative you are.
It also works across a few platforms I have found. Stores and retrieves information successfully on my mac, pc, and in ios. Not sure about browsers or android.
If you needed to set a variable you'd do something like...
attack_xp_required = PlayerPrefs.SetInt ("attack_xp_required_" + username, "{VALUE}");
I'm getting the idea that, in the case where you don't need to manage multiple files and the data is small, PlayerPrefs could be a simple way to save and load data.
I'm just not certain that this is its purpose; the documentation says it's for player preferences.
Do keep in $$anonymous$$d that on Windows it is saved in the registry, so I recommend only using it for data specific to that one machine, and only for data applicable to the whole machine.
I would probably never store a player's score or progress in there.
$$anonymous$$aybe it makes more sense on mobile platforms.
Your answer
Follow this Question
Related Questions
Faster Way to Increment PlayerPrefs Int 1 Answer
Playerprefs, i dont know how to use 0 Answers
How do I use PlayerPrefs properly? 1 Answer
how i save and load my coins look the script please 0 Answers