Editor scripting: Tracking assets of a set type

Hey everyone!
I’m working on a database system of sorts that keeps track of ScriptableObjects throughout the project.
I’m wondering if there’s a way to get notified whenever an asset of a set type is created, deleted, or moved.

I did find AssetPostProcessor which seems to fire off a few events I could use, but if I’m understanding the documentation correctly this only works for imported assets and has no ways of filtering out asset types.
Any advice?

There are a few functions that scriptable objects have even though they’re not monobehaviors

Do those help?

No, because those are runtime functions for instances of the SOs, I’m looking specifically for Editor callbacks.

As I stated before, I did find this on my own but unless I’m misunderstanding the documentation this will not fire when you create a new asset, such as an SO, and it would also fire when assets of different types than the ones I’m interested in are changed.
Of course, type filtering is something I could handle on my own with this, but the asset creation part is the important one.

Okay, I’ll answer that myself: I did misunderstand the documentation and OnPostprocesAllAssets does fire on asset creation.
Only downside to this is when you delete an asset, you cannot check that asset’s type anymore (at least not safely, you can make assumptions based on the file extension but in the case of ScriptableObjects this is useless if you’re only interested in derived types).

Have you tried this? Unity - Scripting API: AssetModificationProcessor.OnWillDeleteAsset(string,RemoveAssetOptions)

That seems to work, yes! However, now when I delete an asset and pass through this, but that throws an error labeled “Failed to unload ‘path of the deleted asset’”, even when I don’t do anything inside that method safe for returning AssetDeleteResult.DidDelete.
This results in the asset still existing on disc and getting reimported…

You have to return AssetDeleteResult.DidNotDelete so unity can internally handle the deletion of the asset
https://docs.unity3d.com/ScriptReference/AssetDeleteResult.DidNotDelete.html

Great, that solved the issue!
Shame that I find out about Addressables today which seems to more or less do what I was intending to do with this system… Oh well, it’s a learning experience :stuck_out_tongue: