Skip to content

Quick Delete PlayerPrefs with Menu Button – Unity

Deleting PlayerPrefs

PlayerPrefs is an excellent tool for saving small pieces of game data such as settings, preferences, and launch counts. However, debugging PlayerPrefs can be a hassle without a method to quickly delete (or restore) them.

Deleting them directly requires delving deep into the folder structure to find the file to delete or creating an ugly temporary debug button. Instead, you can use this script to create a menu item and you’ll be able to delete the PlayerPrefs at any time.

Code

using UnityEngine;
using UnityEditor;

public class DeletePlayerPrefsScript : EditorWindow
{
    [MenuItem("Window/Delete PlayerPrefs (All)")]
    static void DeleteAllPlayerPrefs()
    {
        PlayerPrefs.DeleteAll();
    }
}

And More!

Using a similar method, you could create another method that sets various default values or scenarios that you can use for testing. Just create a new method, change the menu item, and set the PlayerPref values in that.

Hint: Place this script in a folder named Editor to exclude in from your builds.

Published inCode Examples

Be First to Comment

    Leave a Reply

    Your email address will not be published. Required fields are marked *