StartAssetEditing breaks imports

I have a script which works recursively on a folder and changes all the textures’ import details and reimports them all. Looks like this:

foreach (Texture2D tex in Selection.GetFiltered(typeof(Texture2D), SelectionMode.DeepAssets)) {
		string path = AssetDatabase.GetAssetPath(tex);
		TextureImporter texImp = (TextureImporter) TextureImporter.GetAtPath(path);
		texImp.textureType = TextureImporterType.Advanced;
		texImp.maxTextureSize = 2048;
		texImp.npotScale = TextureImporterNPOTScale.ToLarger;
		texImp.textureFormat = TextureImporterFormat.PVRTC_RGBA4;
		texImp.mipmapEnabled = false;
		texImp.isReadable = false;

(Note: this is on Unity Pro iOS)
Well this script doesn’t work because it doesn’t change some of the textures to NPOT “ToLarger”. Which causes him to throw a warning that it can’t compress the texture as it’s not square. One of the goals of this script is to change the texture to square with NPOT ToLarger so it can be compressed.
Apparently some of the textures do get changed. But most don’t.
Can anyone help me with this?

Also note: If I don’t close this script with StartAssetEditing and StopAssetEditing it does actually work but then I don’t see a nice progress bar to show me the progress of the importing (and also the weird unpredictable outcome interests me).

No one has any idea? :frowning: