Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Automatic texture importer not assigning alpha

Discussion in 'Scripting' started by pouria77, Jun 16, 2022.

  1. pouria77

    pouria77

    Joined:
    Aug 13, 2014
    Posts:
    36
    I have written a custom texture importer, and put it in my Editor folder inside the Assets folder, which is supposed to apply my custom settings automatically when a new texture is imported to the project.

    This is my code:

    Code (CSharp):
    1. public class TexturePostProcessor : AssetPostprocessor
    2. {
    3.     void OnPostprocessTexture(Texture2D texture)
    4.     {
    5.         TextureImporter importer = assetImporter as TextureImporter;
    6.  
    7.         importer.textureType = TextureImporterType.Default;
    8.  
    9.         TextureImporterPlatformSettings settings = importer.GetPlatformTextureSettings("WebGL");
    10.         settings.overridden = true;
    11.         settings.name = "WebGL";
    12.         settings.maxTextureSize = 1024;
    13.         settings.format = TextureImporterFormat.DXT5Crunched;
    14.         settings.compressionQuality = 50;
    15.         settings.allowsAlphaSplitting = false;
    16.         importer.SetPlatformTextureSettings(settings);
    17.     }
    18. }
    The issue i have is, when the texture is imported, it doesn't get the alpha channel, but if I manually right click and re-import the texture, then the alpha is applied. You can see that in below image:


    Re-importing is not an option though because our textures will be coming in from external sources automatically, so it needs to have the correct alpha and format the first time.

    Can someone point me in the right direction please?
     
    Last edited: Jun 20, 2022
  2. pouria77

    pouria77

    Joined:
    Aug 13, 2014
    Posts:
    36
    Anyone?
    I'd appreciate any hint to point me in the right direction.