Unity Editor How to Detect a Change of a Specific Component Field

I currently have a component which has two public fields, an “X” and a “Y” position which each represent a cell within a grid. When either of these values change, I want to move the gameobject’s position to be centered on the targeted cell.

So I want to create a custom editor which will change the gameobject’s position when it detects that either the “X” or “Y” value has changed. I know how to do this with a custom built gui, however, these two fields are both created inside DrawDefaultInspector() and as a result, I cannot directly access them. How do I detect a change in either of these individually when they are created and handled by default?

Thank you.

I’ll be honest, I don’t write editor scripts, but I do have several scripts that react to changes in the variables.

What I would recommend trying would be to declare the fields you want to monitor as full properties complete with getter and setter. Then in the setter, in addition to setting the variable, do whatever you want to do when the value changes…

i.e.

private float _x;

public float X {
    get {return _x;}
    set {
        _x = value;
       //Do whatever else you want done when X changes here
    }
}

Hope this helps,
-Larry