Search Unity

Possible to find what control was changed after EndChangeCheck?

Discussion in 'Immediate Mode GUI (IMGUI)' started by CDF, Sep 24, 2015.

  1. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Going out on a limb here, but does anyone know if it's possible to know what control/value was changed after a EndChangeCheck() call?

    e.g:

    Code (CSharp):
    1. EditorGUI.BeginChangeCheck();
    2.  
    3. EditorGUILayout.PropertyField(myProperty); //this is a property which contains other properties, which contain even more properties.
    4.  
    5. if (EditorGUI.EndChangeCheck()) {
    6.  
    7. //some value was changed, but what could it be???
    8. }
    One idea I had was to construct a property/value map before drawing the field, then comparing that property/value map to the property after a change is detected. However, I haven't been able to get values before they change. Every time I compare my values, they always equal the changed value. Maybe there's some event I can check for before a property is modified?

    Another solution is to manually draw the children of the property and check changes per child. This works, but... not when the property has a CustomPropertyDrawer.

    In other words. I don't think it's possible.
     
  2. BMayne

    BMayne

    Joined:
    Aug 4, 2014
    Posts:
    186
    Hey there,

    The changed check just works by every control setting GUI.changed = true when their value has changed. This would not give you the name of the control since it's just a bool. You can however use the hotControl to find out which element is focused. Then when the GUI is changed; check the hotControl. If you map this back to the control you will know which one has changed.

    Cheers,
     
  3. CDF

    CDF

    Joined:
    Sep 14, 2013
    Posts:
    1,311
    Thanks, How does one map the hotControl back to a control?

    I see GUIUtility.QueryStateObject(type, controlId)

    but this assumes I know the type, which I don't. And in any case, the result is always an exception.