Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Custom Inspector to set scene dirty by default with any change

Discussion in 'Editor & General Support' started by Cris_2013, May 16, 2020.

  1. Cris_2013

    Cris_2013

    Joined:
    Nov 25, 2017
    Posts:
    39
    Hi there,

    Is there any way to tell a custom inspector to set scene as dirty with any change at all. At the moment I have to add a change condition to each field and a set scene as dirty when something changes, which makes the code very long and unnecessarily crowded.

    Thanks in advance!
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,888
    Make a custom method that both sets the field value and marks the scene as dirty, then call that instead?
     
  3. Cris_2013

    Cris_2013

    Joined:
    Nov 25, 2017
    Posts:
    39
    That doesn't work with basic fields such as int, float, etc.

    For example, I would like to use float fields like this:
    Code (CSharp):
    1. m_MyFloat = EditorGUILayout.DelayedFloatField(m_MyFloat);
    But I am forced to use them like this:
    Code (CSharp):
    1. EditorGUI.BeginChangeCheck();
    2. m_MyFloat = EditorGUILayout.DelayedFloatField(m_MyFloat);
    3. if (EditorGUI.EndChangeCheck())
    4. {
    5.      EditorSceneManager.MarkSceneDirty(UnityEngine.SceneManagement.SceneManager.GetActiveScene());
    6. }