- Home /
How can I detect an Asset been deleted in Editor by script?
I'm writing a external editor in Unity3D. My asset is inherit from ScriptableObject, and I want to do something when the asset deleted by user through Project Window.
So I first try to write code in ScriptableObject::OnDestroy(), but nothing happend. I read from some others' advice that you should put [ExecuteInEditMode()] to make these OnXXXX function available in Editor. Unfortunately it still not work.
So how can I detect an Asset deleted by user in editor?
Answer by KarasAya · Jun 14, 2011 at 01:43 PM
I think I found the answer. You can use AssetPostProcessor::OnPostprocessAllAssets, there have a parameter _deletedAssets in string[] which give you the deleted assets.
The problem with this approach is that the string doesn't tell you exactly what was deleted or allow you to hook the deletion with a callback.
Your answer
![](https://koobas.hobune.stream/wayback/20220612103844im_/https://answers.unity.com/themes/thub/images/avi.jpg)