Saving to PlayerPrefs from MenuItem script

Hi,

I am saving to PlayerPrefs as follows:

using UnityEngine;
using System.Collections;
using System.Text;
using UnityEditor;

[ExecuteInEditMode]

public class PlayerPrefsTest : MonoBehaviour {


[MenuItem ("GameObject/TestPrefs")]
		static void TestPrefs()
		{
			PlayerPrefs.SetString("testInfo","test four");	
		}




}

Although I can run this from the menu and on the face of it, it runs fine it does not save to PlayerPrefs.

If I go into play mode and run it from the menu it saves fine, no issues.

Is it correct then that you can only save to PlayerPrefs if you are in play mode even from a MenuItem script and ExecuteInEdit mode ?

thanks

I have come across this too and would be keen to know if anyone has an answer.
According to this Unity documentation (here); it uses the PlayerPrefs as a working example in a MenuItem.

Remember to also call PlayerPrefs.Save() to write the cached changes to disk.

… wow! A 9 years old necro!