Changing Texture import default settings.

Every texture that gets imported by Unity defaults to "Filter Mode: Bilinear" and "Aniso Level: 1". I would like to change these defaults to Trilinear and Aniso 0. So I created the following Editor class:

using UnityEngine;
using UnityEditor;

public class TexturePostprocessor : AssetPostprocessor
{
    public void OnPostprocessTexture(Texture2D t)
    {
        t.anisoLevel = 0;
        t.filterMode = FilterMode.Trilinear;
    }
}

Which does work. However I would like to change these values for individual textures manually in the editor after importing. When I do that and then save the scene, OnPostprocessTexture is being called again and resets the manually set values, which is undesirable for obvious reasons.

The documentation says "AssetPostprocessor lets you hook into the import pipeline and run scripts prior or after importing assets.". Why does saving the scene cause a reimport? How can I solve this problem?

It seems I found a solution to my problem:

using UnityEngine;
using UnityEditor;

public class TexturePostProcessor : AssetPostprocessor
{
    void OnPostprocessTexture(Texture2D texture)
    {
        TextureImporter importer = assetImporter as TextureImporter;
        importer.anisoLevel = 0;
        importer.filterMode = FilterMode.Trilinear;

        Object asset = AssetDatabase.LoadAssetAtPath(importer.assetPath, typeof(Texture2D));
        if (asset)
        {
            EditorUtility.SetDirty(asset);
        }
        else
        {
            texture.anisoLevel = 0;
            texture.filterMode = FilterMode.Trilinear;          
        } 
    }
}

You've got to change the settings for the importer, not the texture itself. Changing texture settings is for runtime use.

using UnityEngine;
using UnityEditor;

public class TexturePostProcessor : AssetPostprocessor {

void OnPostprocessTexture () {
    var importer = assetImporter as TextureImporter;
    importer.anisoLevel = 0;
    importer.filterMode = FilterMode.Trilinear; 
}

}

This is solution for me:

public class TexturePostProcessor : AssetPostprocessor
{

	void OnPreprocessTexture()
	{
		Object asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Texture2D));
		if (asset)
			return; //set default values only for new textures;
		
		TextureImporter importer = assetImporter as TextureImporter;
		//set your default settings to the importer here
	}

}

If you want to set defaults for your textures without writing postprocessor code, I made a simple asset that does just this: