- Home /
Getting GUI.skin in editor script changed entire Unity Editor GUI
So I wanted to change some behaviour of the default GUI skin in one of my editor scripts:
GUIStyle style = GUI.skin.button;
style.alignment = TextAnchor.MiddleLeft;
I placed those two lines in the OnGUI function and got the expected behavior, but then I noticed, that all default Unity buttons, like the ones from the player settings or the inspector changed as well. It appears I have permanently changed the default GUI skin. But how and why? I'm very sure, that I only added those to lines and used the "style" variable with a custom button in one of my editor windows, but nothing else.
Now I'm trying to revert back to default settings, but removing the two lines from my script and restarting Unity doesn't change the style back. Is there not easy way like GUI.skin.defaults or something similar?
Thanks!
Answer by Xarbrough · Aug 15, 2015 at 09:25 PM
Sorry to answer my own question, but I found a solution:
To restore the default GUI skin I commented out my old two lines and did
GUI.skin.button = null;
Next, I saved the project, closed it and reopened Unity. The default skin was back.
To get the behaviour I actually wanted, which was to make a copy of the style:
GUIStyle style = new GUIStyle(GUI.skin.button);
style.alignment = TextAnchor.MiddleLeft;
Your answer
Follow this Question
Related Questions
Custom Timeline Playable - GUI Override 0 Answers
How to add a reorderable list on CUSTOM EDITOR WINDOW? 0 Answers
EditorGUILayout.TextField text get's deleted instantly. 2 Answers
Importing .png via script 1 Answer
Maskfield selected values 1 Answer