Simple guide to change Default Sprite Import Settings (FilterMode, Compression, PPU) via script

using UnityEditor;
using UnityEngine;

//Throw this inside YourGame/Assets/Editor/Importer.cs
public class Importer: AssetPostprocessor {

    const int PostProcessOrder = 0;

    public override int GetPostprocessOrder () {
        return PostProcessOrder;
    }

    void OnPreprocessTexture () {
        var textureImporter = assetImporter as TextureImporter;

        textureImporter.filterMode = FilterMode.Point;
        //textureImporter.filterMode = FilterMode.Bilinear;
        //textureImporter.filterMode = FilterMode.Trilinear;

        textureImporter.textureCompression = TextureImporterCompression.Uncompressed;
        //textureImporter.textureCompression = TextureImporterCompression.Compressed;
        //textureImporter.textureCompression = TextureImporterCompression.CompressedLQ;
        //textureImporter.textureCompression = TextureImporterCompression.CompressedHQ;
    
        //textureImporter.spritePixelsPerUnit = 16;
        textureImporter.spritePixelsPerUnit = 32;
        //textureImporter.spritePixelsPerUnit = 64;
    }
}

Note: this can also be done via presets if you somehow know how to do it.

This code will make every sprite image you import default to Point Filter, No Compression and 32 pixels per unit. Original code author is anonymous, and I added Uncompressed and PixelsPerUnity settings to it to make it more flexible.

I know I didn’t invent the wheel or anything since I’m no professional, but finding this code took me way longer than it should, and since I’m happy that I did, I decided to also share. I found it extremely annoying to have to dig through dozens of old threads with outdated methods to change default importer settings, so once I found a working method, I added a few more settings to it to tweak it for pixel art and I am sharing it here for ease of access and spreading the knowledge.

Usage:

  • Create an Editor folder inside your unity project
  • Create an Importer.cs class inside the folder and paste the code above
  • After saving, all imported sprites should follow your settings.

Tested in Unity 2021.1.0f1. Should work most older versions too.

theres already a feature that does this - Import Preset, you can create multiple presets and select which one is active

I didn’t find any tutorials on that that I liked/understood yet, but that’s a good point. I’ll add it as a note about another way to do it on the main post.
Finding that code was easier than finding a decent preset tutorial and they look confusing.

its very simple you just press this button and its done

6974768--822551--Untitled.png

5 Likes

Oh, that sounds simple enough. I feel like I’ve been outsmarted if it just works magically like that, thanks.

its easy to overlook these small buttons