Search Unity

EditorUtility.SetDirty not working - what am I doing wrong

Discussion in 'Immediate Mode GUI (IMGUI)' started by jmcadam2, Aug 31, 2015.

  1. jmcadam2

    jmcadam2

    Joined:
    May 10, 2015
    Posts:
    5
    Hey all. I'm writing a custom editor extension and I'm trying to get unity to recognized changes in the custom inspector. However, when the user tries to exit the scene without saving no prompt comes up to warn about loosing changes made. Here is the simple code.

    using UnityEngine;
    using UnityEditor;
    using System.Collections;

    [CustomEditor(typeof(Random_Move))]
    public class Random_Inspector : Editor
    {

    private Random_Move myGO;

    void OnEnable()
    {
    myGO = (Random_Move)target;
    }

    public override void OnInspectorGUI ()
    {
    EditorGUI.BeginChangeCheck ();

    EditorGUILayout.LabelField ("Radomly place Game Object");
    bool button_state = GUILayout.Button ("Random Move");

    if (button_state)
    {
    myGO.random_move();
    }

    if (EditorGUI.EndChangeCheck()) {
    EditorUtility.SetDirty(myGO);
    }
    }
    }

    When I Debug.log(EditorGUI.EndhangeCheck()) it prints true, but EditorUtility.SetDirty(myGO) doesn't seem to have any effect. After a change is made to the custom inspector by pressing Random Move button, I'll load up another scene or exit Unity and no save prompt is shown.

    Hope this was clear. Help me out if you have any suggestions.

    Thanks