Apply only one Component to Prefab - Editor Scripting


I am doing one extension for Unity and i need to add buttons to Apply certain component to a prefab.

Is that possible through code? So if i have a cube with BoxCollider and MonoBehaviour and i change something on the MonoBehaviour i want to apply to the Prefab, only the changes made, to the MonoBehaviour and not on the BoxCollider…

There is: PrefabUtility.SetPropertyModifications, but that applies all Components, to the Prefab…

If there is no command for this, coud you please suggest some workaround…


  1. Find the prefab source of the instance, there should be API in PrefabUtility.
  2. Confirm the hierarchy relation carefully.
  3. Use GetComponents() to check the component order, in case you have multiple ones of the same type.
  4. Copy instance component’s members and paste to the prefab one you found above.
  5. The method code, to copy and paste component, can be found on Answer or Store. Find the relatives, cheers!