Search Issue Tracker
Won't Fix
Unknown (hidden) 2020.3.X, 2021.3.X, 2022.1.X, 2022.2.X, 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
- Popup windows spawn on the incorrect monitor when the Editor is placed near the boundary of scaled monitor next to a monitor with different scaling
- Hidden Tabs do not shift into empty space after closing visible Tabs
- [Android] Application not deployed on a device when "activity-alias" is used in the AndroidManifest
- Shader compile process adds shader ID to the constant buffer name when the word "Globals" is being used in Vulkan
- Audio Mixer Snapshot link to the documentation isn’t working
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 (2022.1.X):
2022.1.X ports are superseded by 2022.2.X (cancelling port)
Resolution Note (2020.3.X):
2020.3.X ports not supported since it would require fix to also be ported in the package (package workflow not supported anymore). Please use 2021.3.X or more recent.