How can I apply settings for a TextureImporter during post process?

I’ve written an importer for TexturePacker atlases for Unity 4.3 sprites. I’ve managed to nearly get it to where I want it, but I’m running into an issue. Whenever I change the texture/atlas and hop back to Unity, it will reimport the data, and call my OnPostprocessAllAssets.

Everything seems to go smoothly, but the sprites don’t show up correctly immediately. If I change any of the importer settings, then change them back and hit apply, the sprites are perfect. (I can also go into the sprite editor, change something, hit undo, then apply.)

Clearly I’m missing something in the script that’s happens when I hit apply. Any ideas? Can I force that apply myself in code? I’m hoping this is something easy I’ve overlooked in the documentation.

The source code for the importer is here.

In case this isn’t clear enough, I’ve recorded a 3 demonstrating the problem.

Update: It looks like the problem is solved. As GameVortex answered below, I needed to call OnPreprocessTexture, rather than OnPostprocessAllAssets. The updated code is here.

I believe your problem might come from the fact that you are using the OnPostprocessAllAssets function which gets called after the assets have been imported and therefore the modifications to the importer will not take effect until you hit apply.

I do not know how to get it to force an apply through code, but maybe you could use: OnPreprocessTexture instead? It gets called just before the asset gets imported so you can change the settings and they will be applied. This will happen to all textures though so remember to check for the correct one.

Reference to OnPreprocessTexture