- Home /
Editor class "Texture Importer" + Apply import settings question
I created an editor script that helps me change the settings on textures automatically so that I don't have to. It works for the most part except for changing the texture importer isReadable = true. If the texture isn't readable, a dialog box pops open saying "Unapplied import settings" and then asks me to Apply or Revert. Even when I press "Apply", I double-check the texture and isReadable is still set to false. Is there any code that will allow me to "Apply" the import settings?
Here's a snippet of my code (I'm using C#):
string path = AssetDatabase.GetAssetPath(texture); TextureImporter textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
if (textureImporter.isReadable == false) { textureImporter.isReadable = true; AssetDatabase.ImportAsset(path); }
Answer by Digitalos · Jan 02, 2011 at 08:14 AM
I've also been trying to get this working, and have found a few things. This is the bare minimum code you need to get it working, and also it has to be in this order - if you change the filtering/anis/clamp modes, and -then- change the importer settings, it loses the previous changes. This is as of Unity 3.1, tested and confirmed on a Win7 PC.
TextureImporter tImporter = AssetImporter.GetAtPath( path ) as TextureImporter; if( tImporter != null ) { tImporter.mipmapEnabled = ...; tImporter.isReadable = ...; tImporter.maxTextureSize = ...; AssetDatabase.ImportAsset( path, ImportAssetOptions.ForceUpdate ); }
UnityEngine.Object t = AssetDatabase.LoadAssetAtPath( path, typeof( T ) );
if( t != null ) {
( (Texture2D)t ).filterMode = ...;
( (Texture2D)t ).wrapMode = ...;
}
I hope that helps :)
This did work for me. All my old pre-Unity 3.0 texture scripts didn't require a forced update, but now it seems they do.
Answer by Carlos Ulloa · May 22, 2010 at 03:01 PM
You should specify ImportAssetOptions.ForceUpdate when calling ImportAsset, in your case:
AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate);
I just tried that and the dialog box still appears and the same thing that I described before still happens.
i'm experiencing the same issue with trying to procedurally edit import settings. have tried every variation of the ImportAssetOptions, and every Save/Refresh/Load method the AssetDatabase class has to offer. If anyone solves this one, would love to see it posted here.
$$anonymous$$e, too. I noticed that when I try to change multiple textures in a loop only the last showed the question and ignore the changes. All other changes were applied properly!
After looking into it again it shows that all settings apply properly except for the texture currently been previewed in the Inspector window. I'll submit a bug report...
See Favo Yang's answer **
If you click the "revert" button (in s$$anonymous$$d of apply) it actually works. The bug is in the display dialog.
I wonder if this is $$anonymous$$ac only...
Answer by Lucas Meijer 1 · Apr 01, 2010 at 09:03 PM
You'll have more luck when trying a AssetPreProcessor instead. (In fact, I didn't even know you could do what your example shows. Learn something new every day :) )
Here's a link to the help which includes an example usage:
Answer by Favo-Yang · May 31, 2011 at 05:52 AM
I have the same issue by using the texture import settings from Unity Community wiki. If I click apply on the popup, then the current active selection texture object won't get update. Though I didn't find a perfect solution, but if you click revert on the popup, everything works fine.
Confirmed! This also worked when I ran into problems with the $$anonymous$$odelImporter.
Answer by jahroy · Oct 19, 2011 at 03:11 AM
I am reproducing the same issue when using TextureImporter.SetPlatformTextureSettings().
My editor script works fine (and updates the platform override settings) only if the texture in question is NOT selected.
I notice that the texture settings script from the wiki sets Selection.objects to an empty Object array before it operates on textures. I tried using the same approach in my script, but it throws an InvalidCastException.
It might be worth mentioning that (for some silly reason) I'm using javascript...
Your answer
Follow this Question
Related Questions
Auto switch max size of a selected texture in Project window 0 Answers
How do I import TGA, DDS, GIF, PCX and BMP files at runtime? 1 Answer
Texture importer, changing original file size 0 Answers
Any way to export generated bump map from the Editor? 1 Answer
Default Texture Platform/Format settings 2 Answers