Drag and Drop Asset and Default to SubAsset Based on Type?

Unity has some sort of system in place where if you drag an asset into a object ref, it can instead redirect to a subasset. Example: If you import a texture and then make it a Sprite, the sprite is a subobject, but the texture can now be dragged into serialized sprite fields.

Is it possible to define this for custom asset types? I could see a lot of uses for this! It’s almost like an implicit conversion operator, but for drag and drop into serialized fields.

In my particular case, I’ve made a custom graph tool. The graph save file itself is a scriptable and it has a subasset which is essentially the ‘compiled result’ of that graph. I’d like to be able to just drag the parent graph asset into a field of the result type and have the result get assigned automatically.

I’ve searched through the scripting API, but this is a pretty niche question I have trouble even phrasing so I’m unsure where to look. Sub-assets themselves seem pretty sparsely documented.

The graphing API might have something useful in this regard, as it has functionality to guard what can and cannot be connected together.

Here’s a pretty well-done tutorial on it. I don’t know if it would directly apply to the inspector, but it might give you insight to getting something done with your custom asset(s).

I’ve watched that before. It was great for getting started! The graph itself is working fine, it’s just that I store the full graph and only the connected ‘critical path’ of the graph as separate assets of different types. I’d like to be able to drag the graph asset into subasset reference slots in the inspector and have it just assign the subasset directly.