- Home /
Conditional Custom Editor with Popup
I'm trying to show different behavior in my custom editor when selecting an option from a Popup. I used BeginChangeCheck() and EndChangeCheck() to avoid checking the Popup continuously. The problem is that anything GUI related is not shown in Editor then. Any tips on this?
This little example illustrates the problem (I used LabelField elements to keep it simple, but in my code I'm using several Popup and MaskField elements inside each if branch).
EditorGUI.BeginChangeCheck();
selected=EditorGUILayout.Popup(selected,options);
if(EditorGUI.EndChangeCheck())
{
if (selected==0)
{
EditorGUILayout.LabelField("You selected first item"); // Does not work
Debug.Log("You selected first item"); // Works
}
else if (selected==1)
{
EditorGUILayout.LabelField("You selected second item"); // Does not work
Debug.Log("You selected second item"); // Works
}
}
Answer by FortisVenaliter · Apr 11, 2017 at 03:53 PM
So, the Editor GUI will redraw itself all the time. No way around that. What your code is saying is "If it changed on this frame, draw these labels. Otherwise, draw nothing".
You can keep the logs in there so it doesn't spam the console, but you need to bring the LabelFields out of the changecheck block.
Your answer
Follow this Question
Related Questions
How can I make a custom inspector for the Texture Import Settings? 2 Answers
how to know if the lightmap build button has been pressed? 0 Answers
How do I set the current script as the selection in the project view? 1 Answer
EditorGUI.ObjectField placed right below EditorGUI.Foldout? 1 Answer
Does Unity IMGUI for Editor use DirectX on Windows? 0 Answers