Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug TrackPropertyValue not work in SerializeReference

Discussion in 'UI Toolkit' started by watsonsong, Sep 24, 2022.

  1. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I add some test code:
    Code (CSharp):
    1.  
    2. using System;
    3. using UnityEditor;
    4. using UnityEditor.UIElements;
    5. using UnityEngine;
    6. using UnityEngine.UIElements;
    7.  
    8. public class TestBehaviour : MonoBehaviour
    9. {
    10.     public Weapon weapon1;
    11.  
    12.     [SerializeReference]
    13.     public IWeapon weapon2 = new Weapon();
    14. }
    15.  
    16. public interface IWeapon
    17. {
    18. }
    19.  
    20. [Serializable]
    21. public sealed class Weapon : IWeapon
    22. {
    23.     public string name;
    24.     public int damage;
    25. }
    26.  
    27. [CustomPropertyDrawer(typeof(Weapon))]
    28. public sealed class WeaponDrawer : PropertyDrawer
    29. {
    30.     /// <inheritdoc/>
    31.     public override VisualElement CreatePropertyGUI(
    32.         SerializedProperty property)
    33.     {
    34.         var root = new VisualElement { pickingMode = PickingMode.Ignore };
    35.         root.Add(new TextField("Name") { bindingPath = "name" });
    36.         root.Add(new IntegerField("Damage") { bindingPath = "damage" });
    37.  
    38.         root.TrackPropertyValue(property, _ =>
    39.         {
    40.             UnityEngine.Debug.Log("TrackPropertyValue");
    41.         });
    42.  
    43.         return root;
    44.     }
    45. }
    46.  
    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
     
  2. rawna

    rawna

    Joined:
    Aug 13, 2015
    Posts:
    33
    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.
     
    watsonsong likes this.
  3. pegorari

    pegorari

    Joined:
    Nov 19, 2009
    Posts:
    59
    same problem with 2022.2.2f1
     
  4. retronator

    retronator

    Joined:
    Dec 3, 2020
    Posts:
    1
    Same on 2021.3.16f1, except instead of [SerializeReference] I'm editing a property with
    [field: SerializeField].
     
  5. antoine-unity

    antoine-unity

    Unity Technologies

    Joined:
    Sep 10, 2015
    Posts:
    737