- Home /
Bug: GUI.changed inconsistently works
GUI.changed returns true only when the last element in the class structure has been changed. If any other elements have changed, GUI.changed is not set to true.
Here is my simple test. Add the SimpleVector to an empty GameObject. Inspect it and change the x and y offset values. Notice that the message is only printed when you change the y value.
If you replace Vector2 m_relativeOffset with your own class with two elements, you can swap the positions of x and y members in the class structure. Whichever element is last in order in the class definition is the one which will affect whether GUI.changed returns true or not.
// =============================================================================
// File : Assets/Code/SimpleVector.cs
// ============================================================================
///////////////////////////////////////////////////////////////////////////////
// usings
///////////////////////////////////////////////////////////////////////////////
using UnityEngine;
///////////////////////////////////////////////////////////////////////////////
/// SimpleVector
///////////////////////////////////////////////////////////////////////////////
[AddComponentMenu ("GUI/SimpleVector")]
public class SimpleVector : MonoBehaviour
{
public Vector2 m_relativeOffset;
}
// ============================================================================
// File : Assets/Editor/SimpleVectorInspector.cs
// ============================================================================
///////////////////////////////////////////////////////////////////////////////
// usings
///////////////////////////////////////////////////////////////////////////////
using UnityEngine;
using UnityEditor;
/// SimpleVectorInspector
[CustomEditor(typeof(SimpleVector))]
public class SimpleVectorInspector : Editor
{
public override void OnInspectorGUI()
{
DrawDefaultInspector();
if (GUI.changed) {
Debug.Log("SimpleVector + " + this.target.name + " changed\n");
EditorUtility.SetDirty(this.target);
}
}
}
Your answer
Follow this Question
Related Questions
GUI co-ordinates bug? 1 Answer
Impossible: 2 toolbars show being clicked at the same time! 1 Answer
Text rendering bug. Shows black squares. -1 Answers
Canvas wired rotation bug 1 Answer
Character spawn menu bug 0 Answers