Set resizeAlgorithm (Importing Textures)

So, basically, I am trying to set it so my textures imports with bilinear rather than mitchell when it imports my textures.
5371194--543609--upload_2020-1-14_21-41-26.png

But I am having some trouble with this.

I looked up code the best I could and so far I have

TextureImporter importer = assetImporter as TextureImporter;
            importer.GetPlatformTextureSettings("Default").resizeAlgorithm = TextureResizeAlgorithm.Bilinear;

But at the moment, this isn’t working. What am I doing wrong and what is the right way to do it? :slight_smile:

Hey. Sorry to bump this but it’s having quite the profound impact on my game\s visuals and it’s very tedious to manually change every imported texture.

Please help :slight_smile:

Hi @Littlenorwegian ,

You can use AssetPostprocessor and then you need feed TextureImporterPlatformSettings to the TextureImporter’s SetPlatformTextureSettings:

This example I wrote changes those bottom region box settings, naturally you could adjust majority if not every parameter in those import settings at the same time (which are also easier to change…). I also set it so that it only applies this custom import if the folder where the texture is contains word “Sprite” (capitalized.)

public class CustomImport : AssetPostprocessor
{
    // From my notes:
    void OnPreprocessTexture() {
        // Trigger only for asset path that contains word "Sprite"
        if (assetPath.Contains("Sprite")) {
            TextureImporter textureImporter = (TextureImporter) assetImporter;
            Debug.Log("Processing texture " + assetImporter.assetPath);

            textureImporter.SetPlatformTextureSettings( new TextureImporterPlatformSettings {
                maxTextureSize = 32,
                resizeAlgorithm = TextureResizeAlgorithm.Mitchell,
                format = TextureImporterFormat.Automatic,
                textureCompression = TextureImporterCompression.CompressedHQ,
                crunchedCompression = true,
                compressionQuality = 75
            });

            textureImporter.SetPlatformTextureSettings( new TextureImporterPlatformSettings {
                name = "Standalone",
                overridden = true,
                maxTextureSize = 32,
                resizeAlgorithm = TextureResizeAlgorithm.Mitchell,
                format = TextureImporterFormat.RGBA32
            });
        }
    }
}

Important - put this to an Editor folder (anywhere is fine, just make a folder under your Scripts for example.
Otherwise the callback OnPreprocessTexture won’t fire.

If you want to change those basic settings like texture type, just do it like this:

// Sprite settings
textureImporter.textureType = TextureImporterType.Sprite;

textureImporter.spriteImportMode = SpriteImportMode.Single;
...
2 Likes