Search Issue Tracker
By Design
Votes
1
Found in
2018.4
2019.2
2019.3
2019.3.0b7
2020.1
Issue ID
1193450
Regression
No
References to Prefab instance are lost when PrefabUtility.SaveAsPrefabAsset is called by passing the Prefab Instance's clone
How to reproduce:
1. Download and open the attached project "1193450.zip"
2. Open the "TargetScene" Scene
3. Select "TestGameObject" in the Hierarchy
4. Add "Group (2)" GameObject's child as a reference to the TestScript's "go" field
5. Save the Scene
6. Update the "SourceRootPrefab" Asset (Test -> Run (with clone))
7. Select TestGameObject in the Hierarchy
Expected result: TestScript's reference to the child of SourceRootPrefab GameObject is kept
Actual result: TestScript's reference to the child of SourceRootPrefab GameObject is lost
Reproducible with: 2018.4.12f1, 2019.2.10f1, 2019.3.0b8, 2020.1.0a11
Notes:
References to the first level children and Group(1) children of the SourceRootPrefab will be kept, all the other references will be lost.
References of affected GameObjects' components will also be lost.
Affected GameObjects will not have Lightmap applied to them either.
Prefab Utility.SaveAsPrefabAsset was not introduced in Unity 2017.4, therefore the issue was not reproducible
Comments (1)
-
Peter77
Oct 29, 2019 06:17
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
- Shadows are not visible in Player when using DX12 with Forward+ or Deferred+ rendering in URP
- Rendering Debugger Playmode debug UI scrolling is jittery when using click and drag to scroll
- Frame Debugger Target Selection Search Results window becomes too tiny to even see the default “Editor” selection when there are no search results
- Element name field has no character limit in UI Builder
- Async method in Play Mode being aborted when calling `new System.Windows.Forms.Form`
Resolution Note:
The problem here is that the Prefab's GameObjects does not have unique names. This is required for name based replace to retain references. This is stated in the documention:
"If you are saving over an existing Prefab, Unity tries to preserve references to the Prefab itself and the individual parts of the Prefab such as child GameObjects and Components. To do this, it matches the names of GameObjects between the new saved Prefab and the existing Prefab.
Note: Because this matching is done by name only, if there are multiple GameObjects with the same name in the Prefab's hierarchy, you cannot predict which will be matched. Therefore if you need to ensure your references are preserved when saving over an existing prefab, you must ensure all GameObjects within the Prefab have unique names."
https://docs.unity3d.com/ScriptReference/PrefabUtility.SaveAsPrefabAsset.html