Should I cache EditorPrefs or can I write to them every frame?

PlayerPrefs have a save method and it’s pretty clear to me, that I want to cache all of my values at runtime and only write to PlayerPrefs and thereby write to disk once something has changed or at a time, when I want to save all values.

In the Editor, however, it is not totally clear if this general attempt applies. Does Unity write to disk everytime I set a value with EditorPrefs? In that case I probably don’t want to do this in my GUI methods, instead only set when I really want to save. But it could also be that Unity keeps all those values in an internal buffer and only writes them when I hit “Save Project” or close the editor, right?

EditorPrefs is instant. I use it in my EditorWindow like this:

  • OnEnable: LoadPrefs()
  • OnDisable: SavePrefs()
1 Like