Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by jacobschellenberg · Jul 30, 2014 at 02:50 AM · editorcolorplaymodetint

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!

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Deadcow_ · May 16, 2015 at 01:25 PM 0
Share

I don't need to set the tint, but I wander how to get current tint, is this reachable?

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by adamtuliper · Mar 25, 2016 at 09:42 AM

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

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Mar 25, 2016 at 10:35 AM 0
Share

The randomness is a hash value created from the key name "Playmode tint". They most likely added this to avoid name collisions with other keys. The registry is cast insensitive which could lead to problems

avatar image
1

Answer by Bunny83 · Mar 25, 2016 at 11:54 AM

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jmitcheson · Apr 30, 2018 at 10:59 AM 0
Share

What a legend! Thanks for sharing that.

For future travellers: change "m_color" to "m_Color" if the script doesn't work - it must have changed at some point since this was posted.

avatar image
0

Answer by clacey_78 · Feb 29, 2020 at 04:35 PM

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;
         }
     }
 }
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Lukebox · Apr 27, 2021 at 12:07 PM

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"

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

28 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Material doesn't have a color property '_Color' 4 Answers

[Unity Editor] Emulate Touch Input - Still Asking 12/10 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Singleton and MonoBehaviour in Editor 1 Answer

EditorWindow : Change the color of words in a Label String 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges