How To Implement OnValueChages?

I currently using custom setter/getter but it’s not going to trigger if I change it via the inspector. how can I implement OnValueChange that triggers even via inspector like the one in unity UI component?

this is my sample class :

public class StringVariable : ScriptableObject
{
    [SerializeField]
    private string values;
	public Action<StringVariable> OnValueChange = delegate { };

	public string Values
	{
    	get { return values; }
    	set { values = value; OnValueChange.Invoke(this); }
	}
}

Your only option is to implement a custom Inspector for your scriptable object class and invoke your event from there. Note if you want an event where you can assign listeners in the inspector, you have to use a UnityEvent type instead of an “Action”. If you need to pass a parameter to the event, keep in mind that you have to create a concrete non generic derived class in order to use it. See the UnityEvent for an example.

Note that if your class stays this simple, you can use a custom inspector like this:

[CustomEditor(typeof(StringVariable))]
public class StringVariableEditor : Editor
{
    StringVariable m_Target;
    private void OnEnable()
    {
        m_Target = (StringVariable)target;
    }
    public override void OnInspectorGUI()
    {
        Undo.RecordObject(m_Target, "Changed Values");
        m_Target.Values = EditorGUILayout.TextField("Values", m_Target.Values);
        if (GUI.changed)
            EditorUtility.SetDirty(m_Target);
    }
}

Keep in mind that editor scripts need to be placed in a subfolder named “editor”. Also "Editor"s are also scriptable objects so the same rule applies: filename has to match the classname. Note that this custom inspector will just directly read / write to your property and make sure the changes are saved. Therefore your event will be called properly. However you will loose support for multi object editing as well as support for “decorators” like TextArea, Header, etc. If you want to support those, you have to implement an inspector based on the SerializedObject that the inspector provides you. However those always directly work on the serialized data. So you have to provide your own way to ensure the event gets called.

As a final warning: Keep in mind that with such an inspector your event will be called even at edit mode. So whatever code you have inside the listener method will be executed at edit mode as well. So you have to be careful what you actually do in the callback.

Sorry misread your question.

(I am pretty sure that) You cant. Properties arent supported by the editor for a number of sensible reasons. I would suggest thinking about whether or not changing it via the inspector is really any more convenient than setting it other ways.