PrefabUtility.RevertPropertyOverride not working

Hello !
On a big project, I’m trying to create a tool to replace a specified font by another one (in editor), and in the same time revert the overrides that shouldn’t be here.
I’m able to replace the font, but I’ve been searching for hours and I can’t find why my PrefabUtility.RevertPropertyOverride() doesn’t work.

How my code works :

  • I iterate a first time over each prefabs to replace the font
  • I iterate a seconde time over the same prefabs
  • I get every TextMeshProUGUI in a prefab
  • I iterate through every of these
  • I revert the property override like this :
public static void RevertOverrides(IEnumerable<TextMeshProUGUI> texts)
{
    foreach(TextMeshProUGUI text in texts)
    {
          SerializedObject serializedText = new UnityEditor.SerializedObject(text);

          SerializedProperty textFont = serializedText.FindProperty("m_fontAsset");
          SerializedProperty textFontMaterial = serializedText.FindProperty("m_fontMaterial");

          PrefabUtility.RevertPropertyOverride(textFont, InteractionMode.AutomatedAction);
          PrefabUtility.RevertPropertyOverride(textFontMaterial, InteractionMode.AutomatedAction);
    }  
}

My textFont and textFontMaterial aren’t null but their objectOverride property is to false. Am I doing something wrong ?

Unity version : 2020.3.11f1

Hard to tell what the issue is without having a repro project to see how you collect the TextMeshProUGUI objects. If you have nested prefabs or variants you might need to edit the contents of the Prefabs and not the scene instances to remove the overrides. (See Unity - Scripting API: EditPrefabContentsScope)

You can also try checking if they are overridden first before reverting (to make sure they are actually overriden):

PrefabUtility.RevertPropertyOverride(textFont, InteractionMode.AutomatedAction);

Well, you were right about using EditPrefabContentsScope. The thing is that it wouldn’t allow me to RevertPropertyOverride, so I had to copy what was inside the Unity’s github function and paste it instead of using the RevertPropertyOverride