Search Issue Tracker

By Design

Votes

1

Found in

2022.3.50f1

6000.0.23f1

Issue ID

UUM-84303

Regression

No

RegisterValueChangedCallback gets called on the last element of a list when any element is changed

--

-

Reproduction steps:
1. Open the attached “BugRepro” project
2. Open the “Assets/Scenes/SampleScene” Scene
3. In the Hierarchy window, select “TestObject” GameObject
4. In the Inspector, add 2 elements to the “Test List” in the “Test Component” Component
5. Enable the checkbox of the first element in the List
6. Observe the elements in the list and the Console

Expected result: “ToggleProperty in callback _testList.Array.data[0].TestBool“ is logged in the Console and a text field appears in the first element
Actual result: “ToggleProperty in callback _testList.Array.data[1].TestBool“ is logged and the text field appears in the second element

Reproducible with: 2022.3.50f1, 6000.0.23f1
Couldn't test with: 2021.3.45f1 (The elements do not have checkboxes and “No GUI Implemented” is written instead)

Reproducible on: Windows 11
Not reproducible on: No other environments tested

  1. Resolution Note:

    For CustomPropertyDrawers on list or arrays, CreatePropertyGUI is called per item, but the drawer is shared for all items. So any reference that is held will be shared across items. See the note about lists on this page: https://docs.unity3d.com/ScriptReference/PropertyDrawer.html

    References are kept in the user code (_toggleProperty, _testContainer, etc.). So they will all share the reference set during the last item's CreatePropertyGUI. To solve that, you can store references in a struct held in a dictionary per property path, or keep a context using VisualElement.userData on the element created by the drawer. For more info, you can reach out to us on https://discussions.unity.com/tag/ui-toolkit

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.