I would like to detect if a prefab instance has been reverted. Users can revert a prefab instance by selecting a GameObject in the hierarchy and pressing the “Revert” button in the Inspector for example.
I couldn’t find any callback that fires when reverting a prefab. I gave the following two callbacks a try though, but neither does the job:
Anyone from Unity can tell us if there is such a callback now? I’m trying to prevent/protect some variables from “reverting” when using “Revert all”. Would be nice if there was an attribute that could protect some variables (very useful in my case when having auto generated ids for all objects).
The callback does currently not trigger when using “Revert All” (I’m guessing you tested this quickly and is why you created a bug report on this).
Also, it would be nice to have a callback that indicates that the object is about to change/be reverted. Or at the very least - know what action that caused the callback to trigger.
The callback still doesn’t trigger for me when using any of the revert buttons (Revert All, Revert Component, Revert Property). I’m using 2020 LTS and the latest 2022.2. Until this is resolved, is there a different way to detect when the Revert buttons are pressed?
public static event System.Action<UnityEngine.GameObject> prefabInstanceReverted;
public static event System.Action<UnityEngine.GameObject> prefabInstanceReverting;
These callbacks have not been backported yet. Can you check that a 2023.1 build does solve your use case?