Search Issue Tracker
Fixed in 2021.3.18f1, 2022.2.2f1, 2023.1.0a22
MovedFrom attribute doesn't work on prefab overrides
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 [^UUM-6733-MovedFrom.zip]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).
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
- [iOS] Back Triple Camera is not focusing manually and automatically
- Mouse inputs cannot be inputted when searching the Shortcuts Menu by type "Shortcut"
- "Debug Assertion Failed!" error when launching Windows Dedicated Server Player with Script Debugging enabled
- [Cinematic Studio][3D HDRP] Shader warnings thrown in the Console window when creating a new project with Cinematic Studio template
- Autoplay is triggered on Audio Assets when changing Asset Bundle tags