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
- After converting a Built-in project to URP render texture related errors are spammed that can lead to Game view being rendered on top of Scene view
- UI Builder slider value lags and stutters when sliding/modifying certain property values
- "Reset UI Builder Layout" functionality inconsistently changes Canva Size when "Match Game View" is enabled/disabled
- Texture Import Warnings are obscured by other Terrain Layer options in the Inspector
- Burst Inspector middle divider is jittering when resized with the Burst Inspector window docked
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;`.