Changes to AssertImporter in AssetPostprocessor not working as expected [closed]

When I change a property on an AssetImporter within an AssetPostprocessor the unity editor shows the correct settings after import, but the asset does behave as if the default settings are still in place. Only, when I manually apply the importer settings in the editor, the settings will have an actual effect. I am sure I forget something in my code:

public class TilesImportPostProcessor : AssetPostprocessor 
{
	void OnPostprocessModel(GameObject g) {
		ModelImporter importer = assetImporter as ModelImporter;
		importer.globalScale = 1f;
		importer.importMaterials = false;
    }
}

When I import an .fbx from blender, the editor will show a scale factor of 1, but when I place the model into my scene, it is still as small as the default 0.01.

Hi, I think the method you want to implement is OnPreprocessModel (docs here) otherwise the changes you are making are set after they have been used. So I think this should work:

public class TilesImportPostProcessor : AssetPostprocessor
{
    void OnPreprocessModel()
    {
        ModelImporter importer = assetImporter as ModelImporter;

        importer.globalScale = 1f;
        importer.importMaterials = false;
    }
}

You may want to wrap the import settings change in a check to confirm that the model being imported is in fact a model you want to process. I normally query the asset path, something like importer.assetPath.Contains("Models/Tiles/").

Hope that helps.

Thanks a lot! I am so blind; I feel bad. I guess, if you don’t expect a pre-process method in a post-process class, than you don’t see it, even if it is right there in the docs. (I cannot down vote my own question ;-)).

I already have such a check in my actual code, I just wanted to keep the posted code small.