Just hit a wall trying to update a script that was made to modify Sprite Textures by grabbing the TextureImporter (i.e. changing compression formats) to work with the new SpriteAtlas.
When calling AssetImporter.GetAtPath() with a spriteatlas file instead of the hoped for TextureImporter (or ideally some sort of SpriteAtlasImporter) it seems to return something that turns out to be “NativeAssetImporter” when debugged.
Also tried to see if an AssetPostprocessor would offer any options but none of OnPreprocessTexture(), OnPostprocessTexture() and OnPostprocessSprites() seem to get called on reimporting a SpriteAtlas. Only the static method OnPostprocessAllAssets() seemed to register when a SpriteAtlas was reimported.
To date was working with Unity 2017.1.1p3 in the office so tried upgrading to 2017.3.0p2 to see if there were any fixes there. Unfortunately the issue persists even in the newer version.
So as it stands there doesn’t seem to be to modify the SpriteAtlas texture settings via an editor script.
I’m thinking these issues might be bugs as it seems odd if this is all by intent.
Besides this although an improvement in control & flow over the older Sprite Packer the SpriteAtlas does feel lacking in a few other areas.
Variants with different Scale copying the master atlas textures at a different size for downscaled versions instead of repacking isn’t ideal.
Also the [lack of an ETC1 + Split Alpha option]( ETC1 + Alpha Feature page-2#post-3260088) which I had used to keep ram usage down on older Android devices on a previous project is unfortunate.
True it’s easy enough load the SpriteAtlas like that (had already tried) but as far as I can tell there is no access to the texture settings for the SpriteAtlas through itself directly.
Also tried grabbing all the Sprites in the atlas using GetSprites() but the Sprites seem to point back to their original source texture rather than the SpriteAtlas texture. Modifying the texture settings for individual textures has no impact on the settings of the SpriteAtlas. I’ve not tested this but it’s mentioned near the start of the documentation and makes sense.
If you’re curious as to why access to the texture settings is wanted/needed this is in an Asset Bundle building script that runs through updating the texture compression types for assets that are to be built into Asset Bundles for each Android supported compression type. On Unity 5.6 it worked by changing the settings on each Texture directly. Since the SpriteAtlas has those settings in the editor it follows that it should be possible to do the same in a similar fashion for the SpriteAtlas.
Also tried to see if it was possible to write a ScriptedImporter for SpriteAtlas assets to see if that could give an avenue around the issue. The Editor itself rejects trying to replace the native importer though with the error:
“A scripted importer attempted to register file type ‘spriteatlas’, which is handled by a native Unity importer. Registration rejected.”
Would be nice to know if there is something obvious I’ve missed that’d allow me to modify the texture format on SpriteAtlas assets in the way that I require to.
Sorry for not replying earlier and picking up a bit of a zombie thread. It’s possible people already figured out a solution but I think this info could still be useful to others.
For quite a while to updated the AssetBundle texture importer settings I was using an external process to modify the YAML. It worked but was an unpleasant hack so I couldn’t really recommend it. Using the SerializedObject class would have probably been better but I didn’t think of that tbh.
I found out a couple of months ago about the SpriteAtlasExtensions so revisited the system and have since switched over to using them. The code is now much cleaner and shares much of the logic used for processing individual textures thanks to GetPlatformSettings and SetPlatformSettings.
What really brought me back to this thread though was trying to figure out a way to get the master of a variant SpriteAtlas. There’s a SetMasterAtlas but there doesn’t seem to be a getter.
Thanks to DavidZhongIGG’s suggestion, using SerializedObject seems to do the trick:
This is a bit of an old post, but adding using UnityEditor.U2D; to the top of your script adds a lot of extension methods that are useful for modifying sprite atlases, like atlas.Add() and atlas.SetPackingSettings()