Hi. I found that PrefabUtility.SaveAsPrefabAsset() does not work correctly when working with instantiated object.
When you use PrefabUtility.SaveAsPrefabAsset() with GameObject which is instantiated from source GameObject, every call of PrefabUtility.SaveAsPrefabAsset() changes its internal references and structure and it breaks lightmapping information in existing baked scenes.
Here is detailed situation:
Scenes:
SampleSceneA : has RootSourceObject
SampleSceneB : has instance of RootSourcePrefab. And lightmap baked.
Prefabs:
RootSourcePrefab.prefab: generated using SampleSceneA’s RootSourceObject.
If you update RootSourcePrefab by using RootSourceObject, the lightmapping of SampleSceneB is not changed because RootSourcePrefab was replaced with exactly same object. That is correct behaviour.
But if you generate RootSourcePrefab by using the instantiated RootSourceObject and update it like PrefabUtility.SaveAsPrefabAsset(GameObject.Instantiate(RootSourcePrefab)), the lightmapping information of SampleSceneB is lost. This behaviour is incorrect because PrefabUtility.SaveAsPrefabAsset should work as replacement by name policy.
Minimal reproducible project is also attached to Case 1193450.
Thanks.
Edit: I found that references to GameObject is preserved, but references to all of components are lost. (include Renderer, so lightmapping is lost too).