- Home /
 
Solved myself; might be informative to others
inconsistent TextureImporter settings
i'm experiencing some inconsistencies between projects using the same code (an editor script to create textures) & assets.
the following code creates a TextureImporterSettings with various settings.
     var importSettings =  new TextureImporterSettings
         {
             npotScale = TextureImporterNPOTScale.None,
             readable = true,
             mipmapEnabled = false,
             wrapMode = TextureWrapMode.Clamp,
             filterMode = FilterMode.Point,
             maxTextureSize = 1024,
             textureFormat = TextureImporterFormat.AutomaticTruecolor
         };
     importSettings.ApplyTextureType(TextureImporterType.Advanced, true);
 
               then i'm applying them to an asset that i've created using:
             if (savedFilename != "")
             {
                 AssetDatabase.Refresh();
                 var importer = AssetImporter.GetAtPath(savedFilename) as TextureImporter;
                 if (importer != null)
                 {
                     importer.SetTextureSettings(importSettings);
                     AssetDatabase.WriteImportSettingsIfDirty(savedFilename);
                 }
              }
 
               this is only applied to successfully created textures.
inconsistencies arise when i copy the editor script that this code is from to a different project. in one, the texture is (correctly) shown with a type of 'Advanced' but, in another, the type is 'Sprite 2D \ uGUI'.
my only assumption is that by creating importSettings, is that they will be dirty, and therefore written.
any suggestions as to why this might be happening?
thanks in advance.
i've found a way to resolve the problem.
removing this line
 importSettings.ApplyTextureType(TextureImporterType.Advanced, true);
 
                  and then the code after the null check looks like
                 if (importer != null)
                 {
                     importer.textureType = TextureImporterType.Advanced;
                     importer.SetTextureSettings(importSettings);
                     AssetDatabase.WriteImportSettingsIfDirty(savedFilename);
                     AssetDatabase.ImportAsset(savedFilename);
                 }
 
                 Follow this Question
Related Questions
Using Hidden folders for editor stuff? 1 Answer
Initialising List array for use in a custom Editor 1 Answer
Getting direct dependencies for an asset 1 Answer
How do I wait until after AssetDatabase creates an assets before carrying out another function ? 0 Answers
Help with Missing Monobehaviours and Asset Serialization? 0 Answers