As the title says I would like to know if playerprefs can fail to save.

If they can, is there some way to check if it save properly / if it failed?

Example :

if (playerprefsFailed)
    Debug.Log("Failed to save playerprefs...");

I found PlayerprefsException in the Unity API, however I'm confused on how to use it.

I have also googled if they can fail, but couldn't find any results, however considering there is a exception for it, it can probably fail.

The PlayerprefsExceptionis also only thrown on the web player however I would like to know if it can fail, and when, and also how to stop it on a normal pc build.

  • \$\begingroup\$ Maybe the exception is for retrieving data? I couldn't find anything on failing or checking if it fails either. Sorry. \$\endgroup\$
    – Mike Hunt
    Commented Mar 5, 2016 at 17:48
  • 1
    \$\begingroup\$ It seems that, at least currently, PlayerPrefsException is only thrown in Web Player builds when the preference file exceeds the allotted 1MB size: docs.unity3d.com/ScriptReference/PlayerPrefsException.html \$\endgroup\$
    – Joe
    Commented Mar 5, 2016 at 17:55
  • \$\begingroup\$ I'd also suggest that in absence of documentation for it, we can assume that PlayerPrefs.Save() will throw an exception if something goes wrong, but I can't test that right now. \$\endgroup\$
    – Joe
    Commented Mar 5, 2016 at 18:03
  • \$\begingroup\$ @Joe How would I go about testing it? \$\endgroup\$
    – BiiX
    Commented Mar 5, 2016 at 18:13
  • \$\begingroup\$ My best idea on that is construct an environment where the default storage location of PlayerPrefs is unwritable, then try saving. Might not be so easy depending on platform. \$\endgroup\$
    – Joe
    Commented Mar 5, 2016 at 19:04

1 Answer 1


PlayerprefsException will be usually be thrown in web app where 1mb limit gets passed. Docs

To check if playerpref got saved use,

//First time initlisation of playerPref

if( !PlayerPrefs.HasKey("myFloat") || PlayerPref.getFloat("myFLoat") != myFloatValue){
 Debug.Log("Failed to save playerprefs...");
  • \$\begingroup\$ Is it impossible for the PlayerPrefs to save on a non-web game? I mean, lets say the playerprefs file for some reason can't be written to, what will unity do? And how can I alert the player about this issue? \$\endgroup\$
    – BiiX
    Commented Mar 6, 2016 at 16:58
  • \$\begingroup\$ On Windows standalone, there's no need to expect failure. If an application cannot write something into Registry, then something is very wrong with Windows itself. \$\endgroup\$ Commented Mar 10, 2016 at 19:06
  • \$\begingroup\$ @BiiX correctly pointed by maxim ,that may be the reason why unity not implemented exception for it. \$\endgroup\$
    – idurvesh
    Commented Mar 12, 2016 at 5:47
  • \$\begingroup\$ @MaximKamalov Ah, I see. \$\endgroup\$
    – BiiX
    Commented Mar 12, 2016 at 8:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .