- Home /
[ExecuteInEditMode] Update not be called when change object using Editor
Consider this script:
[ExecuteInEditMode]
public class Foo : MonoBehaviour
{
public int m_value;
void Start ()
{
}
void Update ()
{
Debug.Log(m_value);
}
}
and:
[CustomEditor(typeof(Foo))]
public class FooEditor : Editor
{
public override void OnInspectorGUI()
{
base.OnInspectorGUI();
if (GUILayout.Button("Change"))
{
var foo = target as Foo;
Undo.RecordObject(foo, string.Format("Modify {0}", ObjectNames.NicifyVariableName(target.GetType().Name)));
foo.m_value++;
}
}
}
In scene editor, when I hit 'Change' button, value changed, 'asterisk' show up in hierarchy indicating that scene has changed, but no message log in console.
That makes no sense because [ExecuteInEditMode] Update will be called as long as there're any changes in scene.
Any help would be appreciated.
Thanks
Editor scene must be in focus. $$anonymous$$eaning update in editor only run when you hover mouse or click mouse in Editor window scene
And your custom editor must also have execute in editor mode too
Your answer
![](https://koobas.hobune.stream/wayback/20220612163434im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Fill/populate [SerializeField] automatically via script in editor mode? 3 Answers
ExecuteInEditMode not working in some scripts 1 Answer
ExecuteInEditMode not called from namespace 0 Answers
How to generate objects from a script in the editor, i.e. before runtime? 1 Answer
Execute unattached script in Edit Mode 0 Answers