Search Issue Tracker
Won't Fix
Won't Fix in 2023.1.X
Votes
0
Found in
2020.3.42f1
2021.3.14f1
2022.1.23f1
2022.2.0b15
2023.1.0a19
Issue ID
UUM-19944
Regression
No
Serialized List items with "PropertyDrawer" change when adding or removing list items
How to reproduce:
1. Open the attached project
2. Open Scene “SampleScene“ (Assets/Scenes)
3. Select the “Main Camera“ GameObject in the Hierarchy
4. Expand the “Settings“ menu and then, the “Items“ list in the “Example Component” Component
5. Delete two items by pressing the minus symbol at the bottom right of the item list
6. Add an two items to the list by pressing the plus symbol at the bottom of the “Items” list
Expected result: Items are added and removed without affecting the already existing items
Actual result: The already existing items change
Reproducible with: 2020.3.42f1, 2021.3.14f1, 2022.1.23f1, 2022.2.0b15, 2023.1.0a19
Reproduced on: macOS 12.5 (Intel)
Note:
- Might have to delete or remove more items than said in reproduction steps to reproduce the issue
- In newer versions, deleting or adding items affects other items only when changing an existing list item and then adding or deleting a list item (doesn’t work if the changed item is the last one on the list)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Crash on MarkAllDependencies when opening scenes with Assets from the YarnSpinner package
- Crash on CollectAllSceneManagerAndObjectIDs when opening a specific Scene
- GPU device suspended error when replaying a video in the Video Player with NVIDIA Vertical Sync set to Fast
- GPU device suspended error when replaying a video in the Video Player with NVIDIA Vertical Sync set to Fast
- SetComponentEnabled uses class instead of struct when constraining Enableable Component type
Resolution Note:
After investigation, the issue appears to be with the CustomPropertyDrawer code.
Unity reuses property drawers to draw all items, so any variable in it acts as a sort of static reference. So in this case, since we grab the reference of the SerializedProperty on each `CreatePropertyGUI`, only the last one is actually kept, meaning that it only changes the last item in the list.
Make sure to store the value locally to the dropdown instead, by saving it in `userData` for example, and get it back in the callback like so `var value = (evt.target as VisualElement)?.userData as SerializedProperty;`.
Resolution Note (2023.1.X):
After investigation, the issue appears to be with the CustomPropertyDrawer code.
Unity reuses property drawers to draw all items, so any variable in it acts as a sort of static reference. So in this case, since we grab the reference of the SerializedProperty on each `CreatePropertyGUI`, only the last one is actually kept, meaning that it only changes the last item in the list.
Make sure to store the value locally to the dropdown instead, by saving it in `userData` for example, and get it back in the callback like so `var value = (evt.target as VisualElement)?.userData as SerializedProperty;`.