Different playerprefs file for each player on a multiplayer game

Ok so I’m making a little multiplayer game and all player saves are stored on the server so that the players can’t modify them, but of course each player needs their own save file. But it seems player prefs doesn’t allow that. Or does it? I’m not a very good coder so I would like to find a fairly simple way to give each player their own save.

If PlayerPrefs can’t even make seperate files for each player why did Unity bother adding something that has such limited functionality? Do they ever intend to improve it?

Right now I’d be forced to do it in a very shoddy way by doing something like

PlayerPrefs.SetFloat(""+player_username+"/health",health)
PlayerPrefs.SetFloat(""+player_username+"/strength",strength)
PlayerPrefs.SetFloat(""+player_username+"/stamina",stamina)

causing every player’s stats to be stored in the same prefs file, eventually leading to hundreds of different players stats saved into the same file.

This is a problem in the future because eventually I intend to code it to delete save files that haven’t been accessed in more than 30 days. I’m not even sure how’d I’d do that with this system.

If the save data is stored on a server, why even store it in a playerprefs? How about text file, xml or sql or something similar?

Because it wasn’t designed to be used for a multiplayer server. It was designed as a quick way to save information locally for the player.

If you need the performance and capabilities of a database, use a database. If you just need to store a little data for a single user, use PlayerPrefs.

and if you need something inbetween, then minixml / minijson here on the board can be of good use :slight_smile:

PlayerPrefs are for what the name implies: the preferences of the client (player = unity player not the gamer using it), so they are global to this specific application and they use the platforms standard way of storing it. (NSUserdefaults on iOS, registry on windows, …)

If I can figure out a way to save it all to text files that sounds like a good idea. But I’m not sure how to save arrays and other complex things like that to a text file. I’ll try to find some info on it.

I’d need to have each player have their own folder for their username, and inside the folder probably multiple text files, one for their stats, one for a list of inventory items, list of abilities, who knows…