How to do a callback for a UI Element ObjectField?,How to check if UI Element ObjectField was changed?

Hi all,

I’m trying to get an ObjectField (from the UnityEditor.UIElements namespace) working in the GraphView API. Or rather, trying to get a callback to fire whenever the value of the ObjectField changes. It looks something like this:

200963-sfxnode.png

It does not seem possible to fire a callback for the ObjectField the same way as it works for, for instance, the TextField. With a TextField you can do the following:

            TextField textField = new TextField();

            if (onValueChanged != null)
            {
                textField.RegisterValueChangedCallback(onValueChanged);
            }

But when trying to do the same with an ObjectField:

            ObjectField objectField = new ObjectField();

            if (onValueChanged != null)
            {
                objectField.RegisterValueChangedCallback(onValueChanged);
            }

It fails with the following error:

The type arguments for method ‘INotifyValueChangedExtensions.RegisterValueChangedCallback(INotifyValueChanged, EventCallback>)’ cannot be inferred from the usage. Try specifying the type arguments explicitly.

It seems to fail because ObjectField does not implement the INotifyValueChanged interface, while TextField does.

So, my question is: How do I invoke a callback whenever the value of the ObjectField is changed?

Or is there some other way that I am missing?

For ObjectFields you should do something like this:

yourObjectField.RegisterValueChangedCallback(
    evt => {
        Debug.Log("Do something here");
    });

Sorry for being 7 months late…