Search code examples
unity-game-engine

How do I set the Padding value to more than 8 in Sprite Atlass in Unity?


I can't set padding to more than 8. I'm useng Unity 2018.4

enter image description here


Solution

  • A quick google research gave me this thread: https://forum.unity.com/threads/sprites-have-hairline-artifacts-when-using-spriteatlas-and-mipmapping-how-to-fix.713501/

    And someone gave this custom script to set a custom padding value:

    
    using System.Collections;
    
    using System.Collections.Generic;
    
    using UnityEditor;
    
    using UnityEngine;
    
    using UnityEngine.U2D;
    
    using UnityEditor.U2D;
    
    public class SpriteAtlasPaddingOverride
    
    {
    
        [MenuItem("Assets/SpriteAtlas Set Padding 32")]
    
        public static void SpriteAtlasCustomPadding()
    
        {
    
            Object[] objs = Selection.objects;
    
            foreach (var obj in objs)
    
            {
    
                SpriteAtlas sa = obj as SpriteAtlas;
    
                if (sa)
    
                {
    
                    var ps = sa.GetPackingSettings();
    
                    ps.padding = 32;
    
                    sa.SetPackingSettings(ps);
    
                }
    
            }
    
            AssetDatabase.SaveAssets();
    
        }
    
    }
    
    

    Have a nice day.