TrackPropertyValue not work in SerializeReference

I add some test code:

using System;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;

public class TestBehaviour : MonoBehaviour
{
    public Weapon weapon1;

    [SerializeReference]
    public IWeapon weapon2 = new Weapon();
}

public interface IWeapon
{
}

[Serializable]
public sealed class Weapon : IWeapon
{
    public string name;
    public int damage;
}

[CustomPropertyDrawer(typeof(Weapon))]
public sealed class WeaponDrawer : PropertyDrawer
{
    /// <inheritdoc/>
    public override VisualElement CreatePropertyGUI(
        SerializedProperty property)
    {
        var root = new VisualElement { pickingMode = PickingMode.Ignore };
        root.Add(new TextField("Name") { bindingPath = "name" });
        root.Add(new IntegerField("Damage") { bindingPath = "damage" });

        root.TrackPropertyValue(property, _ =>
        {
            UnityEngine.Debug.Log("TrackPropertyValue");
        });

        return root;
    }
}

The ‘TestBehaviour’ has two weapon: weapon1 is normal SerializedField, and weapon2 is SerializeReference.
In the WeaponDrawer, I add a TrackPropertyValue to log information whenever any property changed.
When modify weapon1, the log will show in the console. But modify weapon2, nothing happen.

I am using the Unity 2022.2.0b8

I’m facing the same issue in 2022.2.1f1.

I am currently using TrackSerializedObjectValue as a workaround, but I would prefer if Unity fixed this bug for performance reasons.

1 Like

same problem with 2022.2.2f1

Same on 2021.3.16f1, except instead of [SerializeReference] I’m editing a property with
[field: SerializeField].

Looks like the bug is already logged internally: Unity Issue Tracker - VisualElement.TrackPropertyValue doesn&#39;t invoke the callback when the property is under SerializeReference and SerializeField attributes