Quick summary: When a SerializeReference object creation is recorded in a PropertyModification, and that type is missing, then the error handling is poor, the MovedFrom attribute is not respected, and the data can be lost.
Customer's repro steps:
Have a monobehaviour, ThingContainer, under asmdef A
- Have that mono contains a list of Things, with a SerializeReference attribute
- Decide to move all Things classes under a new asmdef, B
- This will break the SerializeReference lists on all objects created before the change, and can be fixed using the very undocumented MovedFrom attribute
- This will work if in an old scene contains a regular ThingContainer - not as a prefab, it will work an old scene contains ThingContainers in prefabs, without any override on the list
- BUT it doesn't work for all instances of prefabs in scenes that have overrides on the list. In that case you'll get the usual "A field decorated with [SerializeReference] references an unknown managed type!" as seemingly the MovedFrom attribute is ignored.
This is pretty bad as it basically prevents any refactoring / movement of classes used with SerializeReference.
I've tested and reproduced this from 2019.4.37f1 to 2021.3.1f1.
*Internally created repro steps: *
(created 2021.3.6f1, but expect it will reproduce in a similar way on 2021.3 and later)
- Open the [Internal link]project
- Open the scene and confirm there is a prefab instance with overrides on the ThingContainer component, also a regular game object with same content
- Close the scene
- Open the project in visual studio and change the "#if true" line to "#if false". This switches to a renamed version of the referenced class, with MovedFrom attribute.
- Go back to Unity and let it do a domain reload, then reload the scene
- Results: Asserts are hit. And the the prefab instance has lost its elements
The regular game object has the expected behaviour (it hasn't lost its list):
Expected result: The prefab instance shows the 3 elements of the array, just like the regular game object.
Note: The attached project includes code and comments showing how i setup the scene in the first place. We can adapt this into a self-contained automated test (or perhaps add the original scene file to source control).