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. Dismiss Notice

Bug Displaying a list of a custom class

Discussion in 'UI Toolkit' started by Afropenguinn, Jan 2, 2022.

  1. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305
    I have a fairly simple custom class that I'm trying to display a list of in a custom inspector. Here is the custom class:
    Code (CSharp):
    1. [Serializable]
    2. public class TransformTarget
    3. {
    4.     [SerializeField]
    5.     private Transform target;
    6.  
    7.     [SerializeField]
    8.     private Vector2 influence = Vector2.one;
    9.  
    10.     [SerializeField]
    11.     private Vector2 offset = Vector2.zero;
    12.  
    13.     public TransformTarget(Transform target)
    14.         : base()
    15.     {
    16.         this.Target = target;
    17.     }
    18.  
    19.     public TransformTarget(Transform target, Vector2 offset, Vector2 influence)
    20.     {
    21.         this.Target = target;
    22.         this.Offset = offset;
    23.         this.Influence = influence;
    24.     }
    25.  
    26.     public Transform Target { get => this.target; set => this.target = value; }
    27.  
    28.     public Vector2 Offset { get => this.offset; set => this.offset = value; }
    29.  
    30.     public Vector2 Influence { get => this.influence; set => this.influence = new Vector2(Mathf.Clamp01(value.x), Mathf.Clamp01(value.y)); }
    31. }
    Then I have a MonoBehaviour that contains 'List<TransformTarget> cameraTargets'. I have a custom inspector made using uxml that has a property field with 'cameraTargets' as the binding key.

    It displays just fine, exactly how it should, but any sort of modification and it throws an error:
    Code (CSharp):
    1. ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    2. Parameter name: index
    3. System.Collections.Generic.List`1[T].get_Item (System.Int32 index) (at <b7669a6265a143cb8dfcca4048f53d1c>:0)
    4. UnityEngine.UIElements.VisualElement+Hierarchy.get_Item (System.Int32 key) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    5. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    6. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    7. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    8. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    9. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    10. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    11. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    12. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    13. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    14. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    15. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    16. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    17. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    18. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    19. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    20. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    21. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    22. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    23. UnityEngine.UIElements.UIRLayoutUpdater.UpdateSubTree (UnityEngine.UIElements.VisualElement ve, System.Int32 currentLayoutPass, System.Boolean isDisplayed) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    24. UnityEngine.UIElements.UIRLayoutUpdater.Update () (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    25. UnityEngine.UIElements.VisualTreeUpdater.UpdateVisualTreePhase (UnityEngine.UIElements.VisualTreeUpdatePhase phase) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    26. UnityEngine.UIElements.Panel.UpdateForRepaint () (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    27. UnityEngine.UIElements.Panel.Repaint (UnityEngine.Event e) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    28. UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    29. UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    30. UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    31. UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <0d1048bf916c4642bc825dc4f20adde4>:0)
    32. UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <21e44a42102c4fdc82d26c969df8dd2d>:0)
    Any idea what's going wrong?
     
    Last edited: Jan 2, 2022
  2. Afropenguinn

    Afropenguinn

    Joined:
    May 15, 2013
    Posts:
    305