I’m having a hard time unraveling Unity’s complexity with prefabs management and the PrefabUtility.
I made an editor script that adds a few components to the active scene.
I process all game objects that were affected by doing (simplifying a bit)
if (PrefabUtility.IsPartOfAnyPrefab(go))
{
GameObject prefabContainer = PrefabUtility.GetOutermostPrefabInstanceRoot(go);
EditorUtility.SetDirty(prefabContainer);
PrefabUtility.ApplyPrefabInstance(prefabContainer, InteractionMode.AutomatedAction);
}
I would have thought this was enough but it is not applying correctly to the prefabs I want (they always remain as overrides) and considering some scenes have nested prefabs, prefab variants, prefab variants nested into prefabs, and so on, I kind of figured this would happen so what I really need to know is
How do I collect all the prefabs (variants, roots, prefab containers of prefab containers…) that need an “apply” after adding a component to a game object that’s in their (descendant) hierarchy?
Thanks all!