Change TextureType from Script

Hi guys,

I’m working on a automatisation for FBX Files for Avatars and encountered a problem, where I dont really know how to get a workaround.
This is my Code, pretty much the same as in most tutorials:

void OnPostprocessTexture(Texture2D texture)
    if (assetPath.Contains("high_nm"))
        Debug.Log("Normalmap importiert");
        TextureImporter textureImporter = assetImporter as TextureImporter;
        TextureImporterSettings setting = new TextureImporterSettings();

        setting.readable = true;

        setting.textureType = TextureImporterType.NormalMap;



(“high_nm” is the name of the file that gets changed when doing it from hand via the Fix Now Button, so we are working on the right file)

The Problem:

This is how it looks after my code gets executed. The ticked greyscale thing comes from using the convertToNormalmap (Even when I dont use convertToNormalMap it looks the same, so thats not the fault)
This is how the Avatar should look and the settings are, after just importing the Avatar and clicking the Fix now button.

The intresting thing is, if I import it with my script on, and commentate the script out and just change type to Default and back to Normal Map again and hit the apply button it all works.
Does it has to do something with the Apply button? I really have no idea wheres the problem here

I think it has something to do with the Apply button, because if I go into Unity Editor and just click another Type in the Dropdown and put it back to Normal map and hit Apply it looks fine. Anyone has an idea?

Thank you very much guys!

I think the import settings are not being refreshed properly, try " AssetDatabase.Refresh();“, " textureImporter.SaveAndReimport();” or " AssetDatabase.WriteImportSettingsIfDirty(p);"