Unity Editor Playmode Tint Change by Script

Hello,

would anyone happen to know if there is a way to programmatically change the Editor playmode tint, found in Preferences > Colors > Playmode Tint?

I’m looking for something like Editor.Preferences.PlaymodeTint = Color.green
At least that is how I’m expecting it to look.

Thanks!

You can find this in the registry although I’m not sure what the randomness after the string name is.
Ex
HKEY_CURRENT_USER\SOFTWARE\Unity Technologies\Unity Editor 5.x

Playmode tint_h1778814853

As @adamtuliper said the tint color is stored in the registry (at least on windows machines). Unity actually uses EditorPrefs.Get/SetString for this setting. However the inner workings is a bit more complicated as the value is cached in Unity. Of course that’s all handled by internal classes which aren’t exposed as API. So reflection to the rescue. I made a simple helper class that allows you to get and set the tint color:

using UnityEngine;
using UnityEditor;
using System.Linq;
using System.Reflection;
using System.Collections.Generic;

public static class SettingsHelper
{
    static bool m_Initialized = false;
    static FieldInfo m_PrefsField = null;
    static FieldInfo m_PrefColorField = null;
    static MethodInfo m_SetColorPref = null;
    static SortedList<string, object> GetList()
    {
        return (SortedList<string, object>)m_PrefsField.GetValue(null);
    }
    static object GetPref(string aName)
    {
        return GetList()[aName];
    }
    static System.Type GetEditorType(string aName)
    {
        return typeof(Editor).Assembly.GetTypes().Where((a) => a.Name == aName).FirstOrDefault();
    }

    static SettingsHelper()
    {
        var settingsType = GetEditorType("Settings");
        var prefColorType = GetEditorType("PrefColor");
        if (settingsType == null || prefColorType == null)
            throw new System.Exception("Something has changed in Unity and the SettingsHelper class is no longer supported");
        m_PrefsField = settingsType.GetField("m_Prefs", BindingFlags.Static | BindingFlags.NonPublic);
        m_PrefColorField = prefColorType.GetField("m_color", BindingFlags.Instance | BindingFlags.NonPublic);
        m_SetColorPref = prefColorType.GetMethod("ToUniqueString", BindingFlags.Instance | BindingFlags.Public);
        if (m_PrefsField == null || m_PrefColorField == null || m_SetColorPref == null)
            throw new System.Exception("Something has changed in Unity and the SettingsHelper class is no longer supported");
        m_Initialized = true;
    }

    public static Color playmodeTint
    {
        get
        {
            if (!m_Initialized)
                return Color.black;
            var p = GetPref("Playmode tint");
            return (Color)m_PrefColorField.GetValue(p);
        }
        set
        {
            if (!m_Initialized)
                return;
            var p = GetPref("Playmode tint");
            m_PrefColorField.SetValue(p, value);
            string data = (string)m_SetColorPref.Invoke(p, null);
            EditorPrefs.SetString("Playmode tint", data);
        }
    }
}

If you only want to read the current color you could directly use

EditorPrefs.GetString("Playmode tint","");

However the color is encoded / decoded “manually” with two methods in the “PrefColor” class. “ToUniqueString” converts the color inside the PrefColor into that string representation and “FromUniqueString” reads in the color from the string representation and sets the internal color field. You could parse the string manually, if you want but keep in mind it’s an internal format and they can change it whenever they like.

Updates to @Bunny83 's script for 2019 you will need to make the change @jmitcheson mentioned to change “m_color” to “m_Color”.
You will also need to change the name of the settings assembly it’s looking for from “Settings” to “PrefSettings” [Tested with 2019.2.12f1]

var settingsType = GetEditorType("Settings");

to

var settingsType = GetEditorType("PrefSettings");

A simple way to cycle colours during playmode as a test:

[InitializeOnLoad]
public class EditorPlaymodeTintCycler
{
    private static float cycleTimer = 0.0f;

    static EditorPlaymodeTintCycler()
    {
        EditorApplication.update += Update;
    }

    static void Update()
    {
        if (!EditorApplication.isPlaying)
        {
            return;
        }

        cycleTimer += Time.deltaTime;
        if (cycleTimer >= 1.0f)
        {
            cycleTimer = 0.0f;

            float R = Random.Range(0.0f, 1.0f);
            float G = Random.Range(0.0f, 1.0f);
            float B = Random.Range(0.0f, 1.0f);
            Color c = new Color(R, G, B, 1.0f);

            SettingsHelper.PlaymodeTint = c;
        }
    }
}

Still works in 2019.4 with the above fixes applied. Also works for other colors like scene background color, just change “Playmode tint” to “Scene/Background”