I can’t get them to do anything but crash Unity. I would love to see a working example if you have one in which they are used to any effect.
I’d be interested to know if anyone has reliably been able to set texture import settings at all via script. Here’s my attempt, but its behavior is unpredictable. Sometimes it works, and sometimes it doesn’t. I also frequently get the warning message…
Unapplied import settings
Unapplied import settings for “Assets/Textures/test.png”
@MenuItem("Custom/Texture to GUI")
static function TextureToGUI() {
for(var obj : Object in Selection.objects) {
var tex : Texture = obj as Texture;
if(tex) {
Debug.Log(tex.name);
var path : String = AssetDatabase.GetAssetPath(tex);
var i : TextureImporter = TextureImporter.GetAtPath(path) as TextureImporter;
var settings : TextureImporterSettings = new TextureImporterSettings();
i.ReadTextureSettings(settings);
settings.ApplyTextureType(TextureImporterType.GUI, false);
i.SetTextureSettings(settings);
//i.isReadable = true;
i.textureType = TextureImporterType.GUI;
i.textureFormat = TextureImporterFormat.ARGB32;
i.npotScale = TextureImporterNPOTScale.None;
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceSynchronousImport);
}
}
}
@MenuItem("Custom/Texture to GUI", true)
static function ValidateTextureToGUI() : boolean {
return Selection.objects Selection.objects.length;
}
Chiming in here to say I too find the whole TextureImporter script workflow confusing and bizarre.
Also see that error sometimes walkerfx. Especially if trying to manually set format type on a selection of textures.
Looking at the API, seems SetTextureSettings wants a source (without a destination) and ReadTextureSettings wants a destination (without a source)!
Round and round we go! Where it stops? Only UT knows! ![]()
I too get the “Unapplied import settings” message. I would love if UT could post an example of how to change and apply the import settings for a texture.
~ce