Is it safe to put AssetPostprocessor scripts in a pacakge ?

Hi,
According to the documentation :

But what about putting AssetPostprocessor code into a custom package, is it safe ? (as far as I know pacakges are compiled into dll in Library folder)

Bump

I think the idea is that if there’s a compiler error then it won’t import the asset correctly. And if there’s a compile error in the scripts, then custom packages won’t be built, either. So I think the ā€œbest practiceā€ would be to make a DLL of it. You can just take the DLL from the Library/ScriptAssemblies folder which will work. I think.

As I understand it, the dll format is recommended because dll code is always executed where scripts code can be skipped if there are compile errors. With that in mind I’m still confused about scripts code inside a package…I think Unity will try to build package as dll and execute them regardless of compile errors raised in the main assembly but I’m not sure.

Bump, any precision would be appreciated.

OK; just tested it*, and YES a package is fine. Package DLLs are built first even if the main assemblies have compile errors.

  • (with a local package (eg in the Packages folder in the project root) and proper asmdefs in each package; I don’t know what will happen if you don’t have those)

Since you’re here, do you know if there’s a way to toggle on and off an asset postprocessor per file? I only want my PP to run on some files. Thanks!

1 Like

Thanks for your reply !
Unfortunately, I know nothing in the API that allows you direct control over PostProcess for a specific asset. However here is some tricks you can use to do this:

  • Use asset Labels to flag what to process or not. Labels are stored into .meta files so you won’t have to load the entire asset to know if it needs to be post-processed or not.
  • Add an asset name suffixe or custom extension. It will work like the ā€˜Label’ solution but with some path parsing.
  • Store a hashtable of guids that need to be post-processed (or not)
1 Like