Search Unity

Saving a compressed texture with custom mipmaps.

Discussion in 'Editor & General Support' started by Zenix, Aug 31, 2016.

  1. Zenix

    Zenix

    Joined:
    Nov 9, 2009
    Posts:
    213
    I have a procedurally generated Texture2D with custom mipmaps. The texture is generated in an editor script, and I'd like to save it to be used in the build.

    The issue is that if I used Texture2D.EncodeToPNG to save it, then the texture is compressed fine, but I lose my custom mipmaps.

    If I use AssetDatabase.CreateAsset to save it, then by default the texture is uncompressed.

    I can compress the texture before saving by either using Texture2D.Compress or EditorUtility.CompressTexture, however these methods compress the texture to a single format where as I would like to have different formats per platform (pvrtc for ios, etc for android).

    Is there anyway I can save this to disk from an editor script and have it get automatically compressed to the correct format for each platform, without losing my custom mipmaps?