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.
- Some Rigidbody2D.Cast overloads do not correct use the Rigidbody2D angle.
- Same values are being generated if using a random function when “Freeform Light 2D” light is in the scene
- “Unable to use a named GUIStyle without a current skin“ error appears when installing/uninstalling a package if the “Search” window has any text in the search field
- The Animation dropdown in the Animation window can't be opened when Animation is renamed
- [IL2CPP] Building fails when local functions in method with SystemAPI() are used