Reproduction steps:
1. Open the attached “Repro” project
2. Open the “Assets/Scenes/SampleScene.unity” Scene
3. Select the “Assets/A.prefab” Asset in the Project Window
4. Open the “My Script” Script Component’s Context Menu and select “Observe Issue”
5. Observe outputs in the Console
6. Open the “Assets/My Script.cs” Script in a code editor
7. Comment the 8-9 lines, uncomment the 12-13 lines then save
8. Select the “Assets/A.prefab” Asset in the Project Window
9. Observe that the “My Script” Script Component visually has “B (Potato Script)” references in both fields instead of “B” GameObject
10. Open the “My Script” Script Component’s Context Menu and select “Observe Issue”
11. Observe outputs in the Console
Expected result: List element’s reference is correct and “List: ref is null:False ref is destroyed/invalid:False” is outputted
Actual result: List element doesn’t actually reference the GameObject’s Script and “List: ref is null:False ref is destroyed/invalid:True” is outputted
Reproducible with: 2022.3.7f1, 2023.1.9f1, 2023.2.0b5
Couldn’t test with: 2021.3.29f1 (different behavior)
Reproducible on: Windows 10 Pro (22H2)
Not reproducible on: No other environment tested
Note: Using 2021.3.29f1 instead of the Editor automatically assigning the Script reference instead of the GameObject when the field type is changed, the Editor retains the GameObject reference and displays “Type mismatch” in the Inspector window’s field, which is technically correct behavior