Search Issue Tracker
By Design
Votes
3
Found in
2018.4
2019.4
2019.4.5f1
2020.1
2020.2
Issue ID
1269085
Regression
No
Overridden references on Prefab Variants aren't removed from the Prefab file when the reference field is deleted
How to reproduce:
1. Open the attached "1269085 repro" project
2. Open the "PrefabReference" Script from the Assets folder and commend/delete the 5th line
3. From the menu bar select Test > Print Prefab Dependencies
4. Open the Console window and select the printed message
Expected results: "Prefab 2.prefab" isn't listed as a dependency
Actual results: "Prefab 2.prefab" is listed under dependencies
Reproducible with: 2018.4.26f1, 2019.4.8f1, 2020.1.3f1, 2020.2.0a20
Notes:
-The issue seems to only reproduce if the reference is an override to the base Prefab. If the base Prefab contains the reference, the issue doesn't seem to reproduce
-Deleting the reference found under the m_Modifications section of the "Prefab 1 Variant.prefab" file solves the issue and "Prefab 2" no longer gets listed as a dependency
-
rskorski-wizards
Aug 14, 2020 15:46
The real bug here is that the variant will have Prefab 2.prefab listed as a dependency even though a runtime instance wouldn't have a reference to it.
The reference existing in the file is an implementation detail, and not necessarily a bug, . If a member is deleted from the base but then restored, the variant will retain the original value, which is a nice feature to have.
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
- [Dragon Crashers] Build fails in U6
- [Dragon Crashers] 4 Shader error messages on import
- [Dragon Crashers] Readme text is white on light grey
- Cursor stays in front of the first character when entering text in the TextMeshPro field
- Searching in Hierarchy causes unwanted component calls
Resolution Note:
This behavior is by design.
Elaboration:
AssetDatabase.GetDependencies() will return all assets that are referenced by the input asset; these references are not necessarily required during the build process
The imported prefab retains all data from the source asset, this is done to be able to easily edit the prefab and save the results back to the source file, without losing data. This also means that all property overrides remain, even if the target object's field no longer exist.
In a future release of Unity we hope to provide an API for, and possibly a UI to remove all prefab overrides that no longer have valid target's.
Until such a feature lands, it is our recommendation that users implement their own cleanup script.
For example, by
1. Examine all PropertyOverrides of a prefab (PrefabUtility.GetPropertyModifications)
2. Examine if the property still exists (SerializedObject.FindProperty)
3. Remove the override if the property no longer exists (PrefabUtility.GetPropertyModifications/PrefabUtility.SetPropertyModifications)
4. Save the prefab, if it was modified (PrefabUtility.SavePrefabAsset)