I’m trying to duplicate a prefab instance in editor, identically to Ctrl-D.
I am using Unity 2020.3.42
This is my code:
var copy = UnityEditor.PrefabUtility.InstantiatePrefab(prefab, gameObject.transform.parent) as GameObject;
UnityEditor.PrefabUtility.SetPropertyModifications(copy, UnityEditor.PrefabUtility.GetPropertyModifications(gameObject));
The issue is that this seems not not correctly apply changes related to new components added to the prefab instance but not included in the original prefab itself.
Does anyone know how to solve this issue? This almost seems like a bug or oversight to me…