unity-game-engineunity-editorprefab

How can I get override base of Prefab Variant in Unity?


How can I get Prefab Variant's "base" (Field named "Prefab" in picture) from Editor script? I'm on Unity 2022.3, but UnityEditor.PrefabUtility seems do not have corresponding method.

enter image description here

(Please ignore bad namings)


Solution

  • As mentioned by @shingo, PrefabUtility.GetCorrespondingObjectFromSource is a solution. However, you should be careful if your intention is traverse overrides. The method returns Prefab Variant itself which has Original Prefab as its Parent. This is known from 2018, but not (yet?) changed.