Adding a custom AssetPostprocessor.OnPostprocessModel() forcibly re-imports all fbx files

Hi,
I’m trying to implement a custom AssetPostprocessor for my project.

I just created a simple script that does literally nothing:

public classs MyPostprocessor: AssetPostprocessor
{
    private void OnPostprocessModel(GameObject g)
    {

    }
}

After the code is compiled, the editor suddenly re-imports all fbx files without even asking my consent.

  • version: Unity2021.3.16f1
  • I’m using the editor with “Auto Refresh” option disabled, and manually refreshes it myself.

My project contains thousands of fbx files. I can’t work if unity keeps reimporting everything whenever I change a code.

Hi there,

The condition for assets to get re-imported when using Assetpostprocessors are the following:

  • A new postprocessor method for the given asset type was added to the project.
  • A postprocessor method for the given asset type was removed.
  • The AssetPostprocessor.GetVersion value was changed in an AssetPostprocessor class that contains a method for the given asset type.

This is a required process to make sure your assets always get imported correctly. When working in Unity, the AssetDatabse stores information about your source assets in the Assets or Packages folder to accelerate the import process when possible.
For example, when changing target platforms multiple times, we don’t have to re-import all the assets on a previously imported platform because the AssetDatabase already knows the import result and will only restore it instead of doing a full import.

Unity definitely won’t be re-importing every single time you’re making a change, but adding a new method or iterating on an AssetPostprocessor at a time where you would add/remove methods multiple times to test things will trigger a lot of re-imports.
I would suggest copying one or two assets that you want to be impacted by your postprocessor in a separate temporary project to iterate quickly on your postprocessor and then bring the script into your main project once it’s ready to be used.
When iterating on your AssetPostprocessor, I’d also recommend bumping the GetVersion of that AssetPostprocessor when doing changes that you want to be tested to make sure that the AssetDatabase actually re-import your asset instead of bringing back a version from the caching.

1 Like

Thank you for the detailed reply. The process is somewhat cumbersome but understandable. I’ll try what you’ve suggested.

I talk about this problem in technology QQ group. Some people say they dont want to run this code when importing everytime,they just run with one click in some point.Sounds like a button in Editor Menu.