I found PrefabUtility.prefabInstanceUpdated
but sadly it doesn’t work for the prefab asset itself. Is there any better way to do this than using AssetModificationProcessor
?
At the moment I’m using something like this:
public class PrefabModificationProcessor : UnityEditor.AssetModificationProcessor
{
public static string[] OnWillSaveAssets(string[] paths)
{
foreach (string path in paths)
{
if (path.EndsWith(".prefab"))
{
var prefab = AssetDatabase.LoadAssetAtPath<GameObject>(path);
// Do something
}
}
return paths;
}
}
Which detects prefab changes but it’s weird. The method could be called multiple times for the same prefab when I save the prefab once.
Also how can I modify the prefab when the user just updated it? I tried using the code above but it doesn’t work. The prefab asset doesn’t get updated. I tried PrefabUtility.SavePrefabAsset
and setting the asset dirty. No luck.