Please Add OnMainAssetSet callback to AssetPostprocessor

For many, many reasons, it would be incredibly convenient for pipeline customization if we were able to override what sub-asset is set as the “main” asset via an AssetPostprocessor.

One of the most common powerful use cases I can imagine is that there are many times when I and other users have wanted to import a model file (FBX, etc.) but only need the Mesh data from that file - not a whole prefab hierarchy structure. Presently, you can use OnPostprocessModel to delete all the content except the mesh (or meshes, if there are many), but no matter what you do, the ModelImporter will still create a new GameObject to act as the imported prefab root. We also can’t use AssetImportContext.SetMainObject() to set the main object at any point during AssetPostprocessor callbacks (it throws an error).

One of the reasons to build a custom importer that only imports a Mesh - as he main asset - is that if you assign it to an addressable group, then only the Mesh itself will be in the resulting Asset Bundle. As opposed to the current setup where you either assign the root of the whole imported prefab hierarchy to a bundle, or you have to duplicate the mesh out of the model asset - which also breaks the link to the original model file.

Another super common use case would be when you want to import a Model file, but you only want to use its AnimationClip. Being able to override the default main asset with an animation clip would streamline a lot of workflows and get rid of a lot of otherwise useless data.

Another example is when you want to import one of Unity’s standard assets, instead of having the standard type be the root (GameObject, AudioClip, Texture2D, etc.), you actually want to pack it with some extra data by creating a ScriptableObject that references the asset and stores the extra data - then you would be able to make the ScriptableObject be the main asset.

2 Likes

Upon thinking about it more, perhaps a clearer callback name would have been “OnSetMainAsset”. Same idea though.

2 Likes

This would indeed be very, very useful…

1 Like

Yes this would be a life changing feature update… Would definitely want this in my projects :hushed::roll_eyes:

Hey,
I just wanted to share that our team is currently working on new framework for importers (aka Modular Importer).
This new system will allows full control and the customization of Asset Imports. You could see this as the evolution of ScriptedImporters and AssetPostProcessors: defining the output, manipulating the data, adding and/or removing component… flexible and powerful!

Please share any feedback here on through the Public Roadmap, under Asset Import Pipeline / Modular Importer

The Modular Importer allows for full customization of assets import. Through both an API and visual scripting, this new framework will provide:

  • A better (full) control over the import process
  • Improved performance gain
  • Opportunity for an integration with other tools and systems
  • Support for custom features, tailored to pipeline needs

Of course I cannot share any ETA, but it’s in progress!

2 Likes