1

Is there a way to store settings per user in Unity3D game?

I'm looking for something similliar to user.config that can be found in .NET. It is created per computer user.

I need it to store some values (filtering parameters) that can be changed by user/player. It must be possible to save new values too.

If there is no such automagic way what is the best approach? I did consider:

  • Saving to text file.
  • Saving to binary file.
Janusz-kun
  • 89
  • 2
  • 11

1 Answers1

1

I think the PlayerPrefs class should fit your needs. It supports all platforms and provides the basic types like float, int and string including default values.

Under Untiy 3.x PlayerPrefs were reprted to be pretty slow on mobile devices - see the blog entry Writing PlayerPrefs, Fast. I used a modified version of it in several projects and it works fine except for Windows Store apps as they don't support all System.IO classes.

Regardless what solution you take, I would always suggest to encapsulate calls in your own facade class. Thus you can change the underlying implementation and add missing features like array support easily.

Kay
  • 12,918
  • 4
  • 55
  • 77
  • Thanks, for suggesting an alternative. I saw PlayerPrefs earlier but forgot that HKCU in registry is different for each user, which solves the problem for me in Windows. I will later write here if it is fast enough for several (about 20-30) int values on different devices. – Janusz-kun Jan 03 '15 at 16:58
  • 1
    After some time of testing, PlayerPrefs do a good job on Windows. The only thing to remember is to not to call `PlayerPrefs.Save()` all the time but rather with the last of the changes in the bulk (if You change several keys at the same time). – Janusz-kun Jan 15 '15 at 00:23