Search Unity

Question Is there a way to change the import settings for one specific texture through code?

Discussion in 'Scripting' started by MagdielM, Jan 5, 2021.

  1. MagdielM

    MagdielM

    Joined:
    May 27, 2020
    Posts:
    32
    I've written an editor script to generate ramp textures from gradient arrays, and I'm looking for a way to disable mip map generation for the generated texture on import. Looking through the documentation, it seems like
    AssetPostprocessor
    works with file paths, but the script I've written allows the user to select where they'd like to save the texture, and I can't figure out how to pass the user-given path to the postprocessor.

    One idea I had was to use a single static boolean in the
    AssetPostprocessor
    -derived class to control the
    OnPreprocessTexture
    override (or should I say Unity Message?) from my editor script, but on that note, when exactly does
    AssetPostprocessor
    run? My first guess was whenever
    AssetDatabase
    operations occur, but I'm saving the texture to disk using
    System.File.WriteAllBytes()
    rather than
    AssetDatabase.CreateAsset
    and the Improter still runs (although in hindsight, this makes sense). So is it whenever Unity detects changes in the Assets directory? When the texture is clicked and shown in the inspector?

    I'm quite confused.