We are in the process of deprecating Sprite Packer Legacy(SpriteAtlas packing through option of PackingTags in the TextureImporter settings). However we are still allowing existing Assets to continue working with the following constraints :
The Packing Tags box in Texture Importer is now read-only.
Atlases based on Packing Tags are not automatically packed. Requires calling the script using IPreprocessBuildWithReport
Editor Packer Settings only shows Disabled and SpriteAtlas options
We strongly recommend that you start using the SpriteAtlas system which has better functionality, however if for some reason you wish to continue using PackingTags you may need to add the following Editor script.
Editor Settings no longer displays Legacy Sprite Packer options:
Custom Script to force Packing Atlas for Packing Tags:
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
class BuildPreProcessor : IPreprocessBuildWithReport
{
public int callbackOrder { get { return 0; } }
public void OnPreprocessBuild(BuildReport report)
{
EditorSettings.spritePackerMode = SpritePackerMode.BuildTimeOnly;
UnityEditor.Sprites.Packer.RebuildAtlasCacheIfNeeded(BuildTarget.StandaloneWindows64, false);
}
}
Note: BuildPreProcessor class inherits from IPreprocessBuildWithReport, thus it only triggers when building
To migrate existing tag based Atlas to SpriteAtlas, please use the following conversion Script:
using UnityEditor;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEditor.U2D;
using UnityEngine.U2D;
public class PrintAtlas : MonoBehaviour
{
[MenuItem("Atlas/Print Usage")]
static void AtlasedSprite()
{
Dictionary<string, List<string>> TagSpriteMap = new Dictionary<string, List<string>>();
foreach (string s in AssetDatabase.GetAllAssetPaths())
{
TextureImporter ta = AssetImporter.GetAtPath(s) as TextureImporter;
if (ta != null)
{
if (ta.spritePackingTag != "")
{
if (!TagSpriteMap.ContainsKey(ta.spritePackingTag))
{
List<string> newList = new List<string>();
TagSpriteMap[ta.spritePackingTag] = newList;
}
TagSpriteMap[ta.spritePackingTag].Add(s);
}
}
}
AssetDatabase.CreateFolder("Assets", "SpriteAtlas");
foreach (var tagSprite in TagSpriteMap)
{
List<string> assetsforTag = tagSprite.Value;
string alasPath = "Assets/SpriteAtlas/" + tagSprite.Key + ".spriteatlas";
SpriteAtlas sa = new SpriteAtlas();
AssetDatabase.CreateAsset(sa, alasPath);
foreach (var asset in assetsforTag)
{
Debug.Log(tagSprite.Key + " = " + asset);
Texture2D tex = AssetDatabase.LoadAssetAtPath<Texture2D>(asset);
sa.Add(new Object[1] { tex } );
}
}
AssetDatabase.SaveAssets();
}
}
Something to watch out for; so far as I can tell, this script ignores the texture import settings (e.g. compression format, pixel format etc). Not only will the final atlas have different settings from the original sprites, but if the original sprites had different settings, they will still all get lumped into the same atlas, where the old sprite packer would end up making several separate atlases for them. Still, this is a useful start, so thanks! But if anyone knows of a solution that will take the settings into account that would be great!
@rustum , we had to upgrade our unity to 2020, so now as you explained, the Packing Tag is disabled and I had to reorganize our Sprites. I have a few questions about it:
If I now put one of my sprites into a SpriteAtlas, it still has the Packing Tag on it. Is that something I need to worry about?
What about the settings on each sprite. Are they going to be overwritten by the settings on the SpriteAtlas? I’m talking about “Filter mode”, “Compression” and other properties that I find in both places.
If I now put one of my sprites into a SpriteAtlas, it still has the Packing Tag on it. Is that something I need to worry about?
No, once you migrated to Atlas (either using the scripts above) or manually please ensure that SpriteAtlas is set in Editor Settings → SpritePacker Mode. PackingTag will be ignore while building SpriteAtlas Textures.
What about the settings on each sprite. Are they going to be overwritten by the settings on the SpriteAtlas? I’m talking about “Filter mode”, “Compression” and other properties that I find in both places.
Legacy SpritePacker groups sprites based on PackerPolicy (configurable through Scripting Unity - Manual: Sprite Packer (unity3d.com) ). These settings are not migrated to SpriteAtlas automatically as each SpriteAtlas provides the ability to customize these settings per Atlas. Hence please ensure that you set these properties for each Atlas either through Inspector or through Scripting.
Sorry to necro this thread, but this is high on google for this topic and formed the basis of my migration a while back.
Leaving the legacy sprite packing tag set prevents textures that are subsequently made into loose leaf textures from being compressed at all, they should definitely be removed.
I have seen a few instances of this in my project now, some textures that should have been about 1.2MB were 10.5MB. Other textures were ~124KB when they should have been ~14KB.
Notice the suffix “(Atlas)”, this means a legacy packing tag is set and your texture will not be compressed:
Once the tag is removed the texture looks like this:
Here is a script to strip out all the legacy tags, this will not migrate you to the newer system so use with caution. Make sure you back things up too!
using UnityEditor;
using UnityEngine;
public class SpriteAtlasTools : MonoBehaviour
{
[MenuItem("Atlas/Strip Legacy Tags")]
static void StripLegacyTags()
{
AssetDatabase.StartAssetEditing();
foreach (string s in AssetDatabase.GetAllAssetPaths())
{
TextureImporter ta = AssetImporter.GetAtPath(s) as TextureImporter;
if (ta != null)
{
if (ta.spritePackingTag != "")
{
Debug.Log($"Stripping legacy packing tag for: {s}");
ta.spritePackingTag = "";
ta.SaveAndReimport();
}
}
}
AssetDatabase.StopAssetEditing();
AssetDatabase.SaveAssets();
}
}