I am using PrefabUtility.SaveAsPrefabAsset to save a prefab from an AssetPostprocessor. I have another prefab that has an array of GameObjects that reference the other prefabs saved with PrefabUtility.SaveAsPrefabAsset. However, when I look at the saved prefab, all those references say “Missing (Game Object)”.
This is the code I’m using:
GameObject A;
string pathA;
// ... parse files to generate GameObject A
GameObject savedPefabA = PrefabUtility.SaveAsPrefabAsset(A, pathA);
AssetDatabase.SaveAssets();
GameObject B;
string pathB;
// Assign references of savedPefabA to GameObject B's component
PrefabUtility.SaveAsPrefabAsset(B, pathB);
This used to work in Unity 2018 with PrefabUtility.ReplacePrefab() but that method is now obsolete.
If I link the prefabs in editor manually it works but I need to automate this in the AssetPostprocessor. What am I doing wrong?